473,508 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Format decimal thousands

Hi all,
with this code:

decimal? test = 1200345.56m;
decimal? test2 = Decimal.Parse(String.Format("{0:0,0.000}", test));

i can not obtain a decimal value with thousands separators (but without
Decimal.Parse do).

How can i solve?

Thanks in advance
--
Luigi

Sep 15 '08 #1
3 4685
Can you clarify what you are trying to do? A decimal is just a number -
it never really contains any separators. The string version might, but
you've already demonstrated that with your String.Format and Parse usage.

Marc
Sep 15 '08 #2
On Sep 15, 2:15*pm, Luigi <ciupazNoSpamGra...@inwind.itwrote:
Hi all,
with this code:

decimal? test = 1200345.56m;
decimal? test2 = Decimal.Parse(String.Format("{0:0,0.000}", test));
As you have multiple possible decimal separators [BOTH comma AND DOT
are used in different locales] in your string, you will have to use
the Parse function specifying which particular format applies...
>
i *can not obtain a decimal value with thousands separators (but without
Decimal.Parse do).

How can i solve?

Thanks in advance
--
Luigi
Sep 15 '08 #3
I don't see why... both the Format and Parse will take the culture into
account. In the format string the . and , are palceholders for the
decimal and thousand separators (they aren't used verbatim). So this
code should work "as is":

static decimal? TestRoundtrip()
{
decimal? test = 1200345.56m;
string s = String.Format("{0:0,0.000}", test);
decimal? test2 = Decimal.Parse(s);
Console.WriteLine(test2);
return test2;
}
static void Main()
{
decimal? a, b;
Thread.CurrentThread.CurrentCulture =
CultureInfo.GetCultureInfo("fr-FR");
a=TestRoundtrip();
Thread.CurrentThread.CurrentCulture =
CultureInfo.GetCultureInfo("en-GB");
b=TestRoundtrip();
Console.WriteLine(a==b); // returns true
}
Sep 15 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
19218
by: stevek | last post by:
How do I format an integer. Add commas. 1234565 1,234,565 TIA
2
6513
by: Wilfried Mestdagh | last post by:
Hi, I have something like this: string S = dblN.ToString("F4") and S contain the decimal point as in the windows setting (currently ',' on this machine). But I want it to be let's say: '.'...
1
3463
by: nic | last post by:
Hi, I have a textbox value that I need to force (and format) to be a numeric value. For example, I want to allow a user to type 1000 or 1,000 or 1,000,000 but not something that is not numberic....
5
14711
by: Edward Hartfield | last post by:
I'm am relatively new to Python but use it daily. Today, I went looking for a function, like PHP's number_function, that will take a number and return a string with number formatted with grouped...
3
76440
by: Ntl News Group | last post by:
I have a text box that contains the number 1234, I want the value form the text box to display in a second text box so I used: = The problems is that this displays 1234 and I want it to display...
4
2011
by: toffee | last post by:
Hi all, I created a little button which when clicked will run a query on mysql db and output the results as an excel spreadsheet. I do this by setting the header as application excel. All works...
2
12290
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I know how to format a string to use decimal places: Code: Console.WriteLine(string.Format("$ {0:0.00}", 4)); Output: $ 4.00 How would I format a string to use the Thousands Separator? ...
2
1527
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, having a decimal value, like this: decimal? valueTest = 1234567.8999 how can I format it so it appears with thousands separator and 2 decimal digits? Like: 1,234,567.90
2
2636
by: paolo | last post by:
Thanks in advance to everyone that will give me help for these questions. The function formatCurrency is used to auto-format a numeric value with thousands separators and a decimal separator. ...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.