dart如何在帮助下实现Java
BigDecimal b7= b6.multiply(new BigDecimal("0.01")).setScale(2,BigDecimal.ROUND_UP);
将0.052设置为0.06
答案 0 :(得分:0)
如何使用decimal dart package:
import 'package:decimal/decimal.dart';
import 'dart:math';
Decimal setScale(Decimal decimal, int scale, Decimal roundMethod(Decimal decimal)) {
Decimal scaleVal = Decimal.fromInt(pow(10, scale));
return roundMethod(decimal * scaleVal) / scaleVal;
}
Decimal setScaleRoundDown(Decimal decimal, int scale) => setScale(decimal, scale, (val) => val.floor());
Decimal setScaleRoundUp(Decimal decimal, int scale) => setScale(decimal, scale, (val) => val.ceil());
Decimal setScaleRound(Decimal decimal, int scale) => setScale(decimal, scale, (val) => val.round());
void main() {
print(setScaleRound(Decimal.parse('0.052'), 2)); // 0.05
print(setScaleRoundUp(Decimal.parse('0.052'), 2)); // 0.06
print(setScaleRoundDown(Decimal.parse('0.052'), 2)); // 0.05
}