I have one column in database with datatype
decimal(24,10)
Let suppose I have value like
string d1 = "123.6666666666";
Double.Parse(d1)
output in datacolumn : 123.6666666700
I have used Convert.ToDecimal(d1) which gives output 123.6666666666.
Expected output :123.7000000000
The output you got is because the precision of double and decimal values. What you actualy want is to round the number to 1 fractional digit, for that you have to use Math.Round, either with a double or decimal, according to your needs, like this:
Math.Round(Double.Parse(d1),1)
Or, if you need
Math.Round(Convert.ToDecimal(d1),1)
For more information about Math.Round, check the MSDN link: https://msdn.microsoft.com/pt-br/library/75ks3aby(v=vs.110).aspx
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