gpt4 book ai didi

flutter - 删除 Dart 中的小数点

转载 作者:行者123 更新时间:2023-12-03 04:47:10 28 4
gpt4 key购买 nike

我有一个数字:466.62 作为 double 数并且无法将其更改为字符串,如何去掉小数点并打印 46662?我已经设法通过将值乘以 100 得到 46662.0,但我不想打印小数点。谢谢

最佳答案

当您将 466.62 乘以 100 时,您的最终结果也将保持为两倍。这就是您看到 46662.0.0 的原因。所以你需要将它转换为 Int 值,所以你应该这样做:

double vDouble = 466.62 *100
String vString = vDouble.toInt().toString();

这会给你 4662。

对于更通用的情况,请使用字符串 split method ;
String str = '466.62';

//split string
var arr = str.split('.');

print(arr[0]); //will print 466
print(are[1]); //will print 62

关于flutter - 删除 Dart 中的小数点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62077340/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com