I have a string like 000000000100
, which I would like to convert to 1.00 and vice versa.
Leading zero will be remove, last two digit is the decimal.
I give more example :
000000001000 <=> 10.00 000000001005 <=> 10.05 000000331150 <=> 3311.50
Below is the code I am trying, it is giving me result without decimal :
amtf = string.Format("{0:0.00}", amt.TrimStart(new char[] {'0'}));
The "C" (or currency) format specifier is used to convert a number to a string representing a currency amount. Let us see an example. double value = 139.87; Now to display the above number until three decimal places, use (“C3”) currency format specifier.
On the Home tab, click the Dialog Box Launcher next to Number. Tip: You can also press Ctrl+1 to open the Format Cells dialog box. In the Format Cells dialog box, in the Category list, click Currency or Accounting. In the Symbol box, click the currency symbol that you want.
string value = (Convert. ToDecimal(ReturnValue)). ToString("c");
Convert the string to a decimal then divide it by 100 and apply the currency format string:
string.Format("{0:#.00}", Convert.ToDecimal(myMoneyString) / 100);
Edited to remove currency symbol as requested and convert to decimal instead.
you will need to convert it to a decimal first, then format it with money format.
EX:
decimal decimalMoneyValue = 1921.39m; string formattedMoneyValue = String.Format("{0:C}", decimalMoneyValue);
a working example: https://dotnetfiddle.net/soxxuW
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With