Hi!

If you have a look at the implementation of "Decimal.Parse(string)", you
will see that it attempts to parse the string as a number
(NumberStyles.Number), but when you specify "NumberStyles.Currency",
apparently, the treatment of the passed numeric value changes.

I couldn't delve any deeper since the final parsing is done by
"Number.ParseDecimal" which has a non-IL implementation. But presumbly,
passing a different number styles brings a lot of difference, considering
that the default assumption of the style is that as a "Number" and not
"Currency".

Regards,
Gaurav Khanna


----------------------------------------------------------------------------
----------
     *
----------------------------------------------------------------------------
----------
Microsoft MVP - .NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
OpSupport - Spelunking Rotor
http://opsupport.sscli.net/

Read my blog @ http://wic.rediffblogs.com/
----------------------------------------------------------------------------
----------


-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Luca Minudel
Sent: Tuesday, September 02, 2003 9:32 AM
To: [EMAIL PROTECTED]

When I use ToString with a Decimal in this way

    Decimal d = 1237129843M;
    string s = d.ToString("C");

the following way to parse string 's' do NOT work:

    Decimal r = Decimal.Parse(s);

indeed I get a FormatException.
To parse 's' I _have_ to do this way:

    Decimal r = Decimal.Parse(s, NumberStyles.Currency);

Why ToString and Parse methods of Decimal type are not symmetric?
I think this non symmetric design is a bad design because a programmer can
do a ToString while he only know how to specify a format string... then when
he want to parse the sting back he also have to know about NumberStyles.

Can someone explain me this design decision?

TIA (luKa)
http://nullabletypes.sourceforge.net/

===================================
This list is hosted by DevelopMentorR  http://www.develop.com NEW! ASP.NET
courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to