Solved

Currency, doubles, points and comma's

Posted on 2003-12-02
3
604 Views
Last Modified: 2008-02-01
Hello,

My problem:

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?

Thanks!

Razzie
0
Comment
Question by:Razzie_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
testn earned 125 total points
ID: 9858289
You can set CurrencyDecimalSeparator and CurrencyGroupSeparator
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationnumberformatinfoclasscurrencydecimaldigitstopic.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemglobalizationnumberformatinfoclasscurrencydecimaldigitstopic.asp

If you want to make it all over the application, you can set the CurrentCulture....

CultureInfo cul =  new CultureInfo( "en-US", false );
NumberFormatInfo nfi = cul.NumberFormat;
nfi.CurrencyDecimalSeparator = ",";

Thread.CurrentThread.CurrentCulture = cul;
0
 
LVL 18

Expert Comment

by:testn
ID: 9858301
Also you have to use the correct overloading function to convert string to double.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemConvertClassToDoubleTopic10.asp
0
 
LVL 8

Author Comment

by:Razzie_
ID: 9858882
CultureInfo cul =  new CultureInfo( "en-US", false );
NumberFormatInfo nfi = cul.NumberFormat;
nfi.CurrencyDecimalSeparator = ",";

Thread.CurrentThread.CurrentCulture = cul;

---------------------------------------------------------------

Exactly what I was looking for, works perfectly! Thank you!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question