Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi


I need to format monetary values to s9(6)v99 format with leading
zeroes. For example:

string -> Double
002000 -> 20.00
002056 -> 20.56

in c#

what is the way ?

Thanks & Regards
1206
Posted

1 solution

Should be pretty easy:

C#
decimal result = decimal.Parse("002056")/100m;


The numeric types in .NET have Parse() and TryParse() methods to handle the conversion. If you're guaranteed the s9(6)99 format, you can likely get away with Parse().

Use the m suffix to denote decimal types. Decimal gives you the precision you need for currency.

Cheers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900