469,887 Members | 1,958 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,887 developers. It's quick & easy.

decimal.Parse and negative numbers:

Hi,

I am trying to the following:

String s = "( 54.05)";
decimal d = decimal.Parse(s);
when s = "( 54.05)" I what the value -54.05
and s = " 54.05" I what the value 54.05
Any suggestion.

Thanks.

Nov 17 '05 #1
2 16823
Use the default formatting that Decimal expects, or specify the formatting that you are using:

Decimal.Parse(myString, System.Globalization.NumberStyles.Currency)

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"probashi" <pr******@hotmail.com> wrote in message news:11**********************@z14g2000cwz.googlegr oups.com...
Hi,

I am trying to the following:

String s = "( 54.05)";
decimal d = decimal.Parse(s);
when s = "( 54.05)" I what the value -54.05
and s = " 54.05" I what the value 54.05
Any suggestion.

Thanks.

Nov 17 '05 #2
Than choose the correct style that matches your input from the System.Globalization.NumberStyles enumeration.

If the enumeration does not support your needs, you'll have to parse the string manually. In this case, I suggest using a Regex.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"probashi" <pr******@hotmail.com> wrote in message news:11*********************@o13g2000cwo.googlegro ups.com...

Decimal.Parse(myString, System.Globalization.NumberStyles.Currency)

is throwing Format Exception.

Dave wrote:
Use the default formatting that Decimal expects, or specify the

formatting that you are using:

Decimal.Parse(myString, System.Globalization.NumberStyles.Currency)

--
Dave Sexton
dave@www..jwaonline..com

-----------------------------------------------------------------------
"probashi" <pr******@hotmail.com> wrote in message

news:11**********************@z14g2000cwz.googlegr oups.com...
> Hi,
>
> I am trying to the following:
>
> String s = "( 54.05)";
> decimal d = decimal.Parse(s);
>
>
> when s = "( 54.05)" I what the value -54.05
> and s = " 54.05" I what the value 54.05
>
>
> Any suggestion.
>
> Thanks.
>

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Gustaf Liljegren | last post: by
2 posts views Thread by Piotr | last post: by
3 posts views Thread by JenHu | last post: by
4 posts views Thread by =?Utf-8?B?cGF0cmlja2RyZA==?= | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.