Difference between 3 types of parsings for string to decimal

  • Thread starter Thread starter sushant.bhatia
  • Start date Start date
S

sushant.bhatia

Whats the difference between :-

1. Convert.ToDecimal(stringNumber)
2. Decimal.Parse(stringNumber)
3. decimal.Parse(stringNumber)

Thanks.
Sushant Bhatia
 
Sushant,

Can you give me an idea in what relation your question is placed.

Convert.ToDecimal(stringNumber);
this overloaded method from Convert.ToDecimal does probably exact the same
as
decimal.parse(stringNumber)

Decimal.Parse gives an error.

Cor
 
Hi Sushant Bhatia,

The Convert class is designed to convert a wide range of Types, so you can
convert more types to Decimal than you can with Decimal.Parse, which can
only deal with String. On the other hand Decimal.Parse allows you to
specify a NumberStyle.

Decimal and decimal are aliases and are equal.

For Convert.ToDecimal(string), Decimal.Parse is called internally.
 
Whats the difference between :-

1. Convert.ToDecimal(stringNumber)
2. Decimal.Parse(stringNumber)
3. decimal.Parse(stringNumber)

Convert.ToDecimal returns 0m if you pass in null.
System.Decimal.Parse and decimal.Parse are exactly equivalent, as
decimal is just a C# shorthand for System.Decimal.

System.Decimal.Parse will throw an ArgumentNullException if you pass in
null.
 
Back
Top