想知道如何像 int number 一样显示这个结果
var symbol = data[index]["symbol"];
double cureentprice = datarates["price"]["$symbol"];////this double is 1.17150
double enrty = double.parse(data[index]["entryprice"]);////this is 1.17100
double lo = cureentprice - enrty ;//i got like this result 0.00050
正如你在上面看到的,我得到的结果是 0.00050,但我需要像这样的 50
有什么想法可以做这样的事情吗??
答案 0 :(得分:1)
试试这个。也许这应该有帮助。如果这不起作用,请告诉我。
var symbol = data[index]["symbol"];
double cureentprice = datarates["price"]["$symbol"];////this double is 1.17150
double enrty = double.parse(data[index]["entryprice"]);////this is 1.17100
// double lo = cureentprice - enrty ;//i got like this result 0.00050
int scale = 100000;
double lo = currentPrice - enrty;
var value1 = (lo * scale).floor();
var value2 = (lo * scale).ceil();
print(value1);
print(value2);
答案 1 :(得分:1)
您可以先缩放,然后使用 floor() 或 ceil() 函数进行四舍五入以获得所需的输出。
double currentPrice = 1.17150;
double enrty = 1.17100;
int scale = 100000;
double lo = currentPrice - enrty;
print((lo * scale).floor()); //prints 49
print((lo * scale).ceil()); //prints 50