How to round of a decimal to the nearest value?


#1

I have a number 129454.92. I want to round it off to 1,29,455.00. The other problem is that when I read the excel file the column containing these values are converted to string type. I will have to convert it to double. How do I do that?


#2

@ovi @arivu96


#3

Hi @jamnanin,

Math.Round(1.2) ==> 1 Math.Round(1.5) ==> 2 Math.Round(2.5) ==> 2

If you don’t want to round the value just convert into int.

Regards,
Arivu


#4

@jamnanin, You can also use this,

string.Format(System.Globalization.CultureInfo.GetCultureInfo("en-IN"),"{0:n}",Math.Round(Convert.ToDouble(129454.92)))

Reference : How to convert String Datatype value in Comma separated value?

Regards,
Dom :slight_smile:


#5

Thanks @arivu96 and @Dominic. @Dominic your solution worked.