#### How can I convert string to decimal with trailing zero(s)

Total Post:28

Points:196

1996  View(s)
Ratings:
Rate this:

Suppose that we have stringvalue=125.32600 when it convert to decimal value with this code

```decimal d;
decimal.tryparse(stringvalue,out d)```

d value is 125.326 how can I do this convert with final result 125.32600

1. ##### Re: How can I convert string to decimal with trailing zero(s)

Your code works as written (as long as the decimal separator matches your culture):

```decimal d;
decimal.TryParse("125.32600", NumberStyles.Number, CultureInfo.InvariantCulture, out d);
s = d.ToString(CultureInfo.InvariantCulture); // 125.32600```

Decimal already remembers how many trailing zeros it has. This is caused by decimal representing numbers in non-normalized form, with an integer mantissa and an exponent representing the number of decimal digits. e.g. 125.32600 is represented as 12532600 * 10^-5

Modified On Mar-31-2018 05:40:41 AM

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.

10-B Taskand Marg, Near Patrika Chauraha, Civil Lines, Prayagraj, UP, India-211001.
contact@mindstick.com
91-532-2400505

969-G Edgewater Blvd,Suite
793 Foster City-94404, CA (USA)
+1-650-242-0133