How can I format a decimal to be converted to a string without group separators and without decimals?
For eg: "1,234.56" should be displayed as "1234".
This almost works, but rounds up:
Decimal d = 1234.56M;
string s = string.Format("{0:0}", d);
Console.WriteLine(s);
Outputs: 1235
As @Jon Skeet suggested, you could cast to an integer type (assuming it was large enough to hold your largest decimal value):
Decimal d = 1234.56M;
string s = string.Format("{0}", (long)d);
Console.WriteLine(s);
Outputs: 1234
Demo: http://ideone.com/U4dcZD
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