Solved

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

Posted on 2006-11-02
2
217 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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

632 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