Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-11-02
2
Medium Priority
?
219 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
[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 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

730 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