Format a string for cents only in C# -


i have dollar amount, 23.15. want format can return .15 or 15 want place cents in html <sup> tag.

to return dollars only, used {0:c0} or without $ sign {0:n0}

edit: apparently {0:c0} , {0:n0} not work me round whole number :(

if need string html tags can use this:

 var decimalvalue = 23.15m;  string value2 = decimalvalue.tostring("$ #.<sup>##</sup>"); //$ 23.<sup>15</sup> 

also if want amount cents instead of

var value =  string.format("{0:c0}", decimalvalue); // $23 

use

 var value =  string.format("{0:c2}", decimalvalue); // $23.15 

zero after 'c' in '{0:c0}' format means number of signs after point.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -