Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to fix double in flutter even if the last decimal is 0

Hi so i have a double seems like this

d1 = 12.106

and i need to show in to a string ‘12.130’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 double num1 = double. parse((12.3404). toStringAsFixed(3));

well i expected to return "12.130" but it returned "12.13"

the thing i need a string "12.130" instead "12.13"

 double num1 = double. parse((12.3404). toStringAsFixed(4));

so tried this one again but also failed

well then number must be shown 3 decimals even if the last is 0

where or what should i have to fix?

>Solution :

I understand you have the following variable:
double d = 12.130;

and now you want to convert it to a string with the following value: String s = "12.130"

This should work:
String res = d.toStringAsFixed(3) //"12.130"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading