Reputation: 5
I have this number: 11,806.206193333.
I was using Math.Truncate(val * 100) / 100 to hopefully change to 11,806.20.
But the outsome came out to be 11806.00. What went wrong?
Thanks.
Upvotes: 0
Views: 74
Reputation: 564373
Your logic is correct. This works perfectly:
decimal val = 11806.206193333m;
decimal truncated = Math.Truncate(val * 100) / 100;
Console.WriteLine("{0:N2}", truncated);
This will print 11,806.20
(on a US-English system).
Upvotes: 4