Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Format a decimal with Culture Info and thousand separators

Posted on 2009-04-04
1
Medium Priority
?
5,163 Views
Last Modified: 2013-12-17
I have a value in the database that is stored using the en-US culture info number formatting:
20802.10549248

I want to display this value in my .Net C# web app using the user's CultureInfo.CurrentUICulture.NumberFormat, including the thousand separators.  But I also do not want to truncate any of the decimal places.

So, if the user's Thread.CurrentThread.CurrentUICulture is set to "en-US", I want the number to show as:
20,802.10549248

If the user's  Thread.CurrentThread.CurrentUICulture is set to "fr-BE", I want the number to show as:
20.802,10549248

I have only seen solutions that specify a certain number of decimal places, which would truncate my value.  Right now I have the code as follows:
return ((double)value).ToString(CultureInfo.CurrentUICulture.NumberFormat);
However, this doesn't insert the thousand separator as I want it to.

I also tried variations on:
return ((double)value).ToString("n", CultureInfo.CurrentUICulture.NumberFormat);
Which all insert the thousand separator, nut "n" truncates to 2 decimal places and any number (i.e. 0 or 2 or 10) after the "n" truncates the decimals or adds padding zeros.

Does anyone have a solution for this seemingly simple problem?

Thanks in advance!
0
Comment
Question by:chinacat456
[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
1 Comment
 
LVL 22

Accepted Solution

by:
pivar earned 2000 total points
ID: 24069083
Hi,

How about (you can use as many # as decimalholders as you like, they will only be shown if the digit is significant)

return ((double)value).ToString("#,0.#############", CultureInfo.CurrentUICulture.NumberFormat);

/peter
0

Featured Post

Hire Technology Freelancers with Gigs

Work with 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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

636 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