Solved

500pts: Formatting a number to us . as decimal holder

Posted on 2006-11-02
2
207 Views
Last Modified: 2010-04-16
Hi there,

Can anyone help.. The machine i work on is in a european culture which mean decimal points are comas and comas are decimal points

i.e 20,000.45

here is 20.000,45

Hence I have a figure that arrives in a string in the form of 20.000,45 and i convert it to a double which i store in tempDouble ... at this stage it is good.. tempDouble = 20,000.45 so now i need a string representation of it .. so i do ToString ... but his converts it back to

20.000,45

System.Globalization.NumberFormatInfo nfi = new System.Globalization.NumberFormatInfo();
                                                      nfi.NumberDecimalSeparator = ",";
                                                      nfi.NumberGroupSeparator = "";
                                                      nfi.NumberDecimalDigits = 2;      
                                                
                                                      tempDouble = double.Parse(valor,nfi);
                                                      valor = tempDouble.ToString();

What am i doing wrong?? Obviously the ToString is using the culture setup of the machine

ANy ideas?

Thanks inadvance

Ian
0
Comment
Question by:ianinspain
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 17858252
You need to use Double.ToString Method (IFormatProvider) overload (here and in any other place, read FxCop guidelines). ToString function without parameters depends on the current culture. To get standard number representation, use ToString(CultureInfo.InvariantCulture).
0
 

Author Comment

by:ianinspain
ID: 17858449
excellent! thanks.. works a treat!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now