-3

I need 45.7 to be 45.70

Math.Round(d, 2) have no effect. Have tried with decimal and double type.

I would appreciate any kind of help.

user1281991
  • 763
  • 1
  • 12
  • 34
  • A number (of whatever numeric type) is never going to have extraneous 0s - they mean nothing. You have to convert it to a string. – neminem Mar 09 '15 at 22:59
  • The values `45.7` and `45.70` are the same. Actually the value is not stored in that form at all, but in the form `(1 + 0.428125) * 2 ^ 8`, it only looks like `45.7` when you format it into a decimal number to display it. – Guffa Mar 09 '15 at 23:21
  • @neminem It is not actually true that a number of the decimal type "is never going to have extraneous 0s". Try this, for example: `Console.WriteLine("{0}\t{1}", 1m, 1.00m);` (Of course, that doesn't help answer this question, since it is clear that the OP's needs to understand string formatting, as you suggest.) – phoog Mar 10 '15 at 17:04

1 Answers1

0

You need to apply a string format:

string.Format("{0:N2}", 45.7)

Check here for docs on the string formatters

Toby Crawford
  • 787
  • 5
  • 6