472,958 Members | 2,310 Online

# 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?

--
Luigi

Sep 15 '08 #1
3 4655
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

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?

--
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;
CultureInfo.GetCultureInfo("fr-FR");
a=TestRoundtrip();
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.