Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 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