Created
February 11, 2022 15:44
-
-
Save saliouseck2009/db1c639a8681deebf8f0554c2e63988d to your computer and use it in GitHub Desktop.
help you get closest string representation with exactly N digits after the decimal point, then parse the result to double
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double num1 = double.parse((12.3412).toStringAsFixed(2)); | |
// 12.34 | |
double num2 = double.parse((12.5668).toStringAsFixed(2)); | |
// 12.57 | |
double num3 = double.parse((-12.3412).toStringAsFixed(2)); | |
// -12.34 | |
double num4 = double.parse((-12.3456).toStringAsFixed(2)); | |
// -12.35 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment