Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert to double with 2 precision - string after dot?

I want to convert this string: 0.55000000000000004 to this double: 0.55. How to do that?

like image 559
MonsterMMORPG Avatar asked Feb 14 '11 20:02

MonsterMMORPG


People also ask

Which function will convert a String into a double?

In the C Programming Language, the strtod function converts a string to a double. The strtod function skips all white-space characters at the beginning of the string, converts the subsequent characters as part of the number, and then stops when it encounters the first character that isn't a number.

How do you convert text to double in flutter?

Using parse() For converting a String to a double, the parse() static method of double class can be used. String source, [@deprecated double onError(String source)?] );


1 Answers

you can use this code to reduce precision part:

double m = Math.Round(0.55000000000000004,2); 

Result would be : 0.55

like image 183
mjyazdani Avatar answered Oct 08 '22 10:10

mjyazdani