首页 > 解决方案 > 如何在小数点后取两个数字,数字为-7.922816251426434e+28 in flutter

问题描述

我只需要在小数点后取两个数字,我在 json 响应中得到奇怪的数字,我必须处理这些数字,比如 -7.922816251426434e+28

HoldedQuantity.toStringAsFixed(2);

我刚刚尝试了这种方法但不起作用,我该如何处理颤振飞镖中的这些数字请帮忙

标签: flutterdartroundingpointsdecimalformat

解决方案


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));

1.toStringAsFixed(3);  // 1.000
(4321.12345678).toStringAsFixed(3);  // 4321.123
(4321.12345678).toStringAsFixed(5);  // 4321.12346
123456789012345678901.toStringAsFixed(3);  // 123456789012345683968.000
1000000000000000000000.toStringAsFixed(3); // 1e+21
5.25.toStringAsFixed(0); // 5

推荐阅读