-1

I want to add precision to the decimal value. For example, I have this value:

decimal number = 10;

I want to make it 10.00. I don't want to convert it to string like number.ToString("#.00")

Currently, I have this method:

decimal CalculatePrecision(decimal value, int precision)
{
    var storedCalculated = decimal.Divide(1, Convert.ToDecimal(Math.Pow(10, precision)));
    return value + storedCalculated - storedCalculated;
}

Is there any good solution for this?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Dilshod K
  • 2,924
  • 1
  • 13
  • 46

2 Answers2

1

You can't. 10 and 10.00 are the same number. Only the "presentation" is different. Both "presentations" are strings. The actual number look different. If you need to change the presentation, convert to string.

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
0

How about

 decimal d = 10;
 d += 0.00M;
 Console.WriteLine(d);

Try reference

Math.Round not keeping the trailing zero

How do I display a decimal value to 2 decimal places?

MichaelMao
  • 2,596
  • 2
  • 23
  • 54