The question is: do you really need the accuracy stored in decimal form, and not just displayed the decimal digit with the required accuracy. Most applications know internally how accurate they want to be and demonstrate this level of accuracy. For example, even if the user enters an invoice for 100 in the batch of accounts, he still prints as 100.00 using something like val.ToString ("n2").
How can i create b from? How to create b from c?
c to b.
Console.WriteLine(Math.Round(2.00000000m, 1))
produces 2.0
a to b is difficult because the concept of introducing precision is a little foreign to mathematics.
I think that a terrible hack can be both ways.
decimal b = Decimal.Parse(a.ToString("#.0")); Console.WriteLine(b);
produces 2.0
sgmoore Jul 15 '09 at 18:03 2009-07-15 18:03
source share