Currency, doubles, points and comma's
Posted on 2003-12-02
I have difficulties with prizes in my database to convert and display correctly.
I'm using a MySQL database, the field of the prizes is set to varchar(255) (don't ask me why, I didn't design it) and the prizes are stored with a point not a comma.
I try to convert a prize like "12.50" using Convert.ToDouble(). However, if I try display this result it gives me '125'. So it leaves the point, AND the zero.
I want everything to displayed as 12,50. And I must be able to do some necessary calculations with the database result as well. What is the best way to do this? I know it could probably be done by replacing the point in the string to a comma and convert everything to double and then do some necessary calculations, and then convert it back to string so I can replace the point again for the comma... or something like that... but I don't like that obviously.
In java you have some Currency format or something. I'm sure in C# it can be done by using some sort of IFormatter or Culture settings, but I know nothing about them. So, what is the best way to do this without touching the database format?