莫 莫征文 Unregistered / Unconfirmed GUEST, unregistred user! 2002-06-03 #1 一个数据,小数点后可能有两位以上, 用四舍五入的方法仅保留其中两位,这样的操作什么实现? 如:1023.453=1023.45 1023.456=1023.46
H hjandy Unregistered / Unconfirmed GUEST, unregistred user! 2002-06-03 #2 function DoubleToDollar(ADouble: Double): Double; begin Result := StrToFloat(FloatToStrF(Floor(ADouble * 100 + 0.51) / 100.0,ffFixed, 15, 2)); end; function DoubleToDollarStr(ADouble: Double): String; begin Result := FloatToStrF(floor(ADouble * 100 + 0.51) / 100.0, ffFixed, 15, 2); end; function DoubleToStr(ADouble: Double; Digits: Integer): String; begin Result := FloatToStrF(ADouble, ffFixed, 15, Digits); end;
function DoubleToDollar(ADouble: Double): Double; begin Result := StrToFloat(FloatToStrF(Floor(ADouble * 100 + 0.51) / 100.0,ffFixed, 15, 2)); end; function DoubleToDollarStr(ADouble: Double): String; begin Result := FloatToStrF(floor(ADouble * 100 + 0.51) / 100.0, ffFixed, 15, 2); end; function DoubleToStr(ADouble: Double; Digits: Integer): String; begin Result := FloatToStrF(ADouble, ffFixed, 15, Digits); end;
J jack0424 Unregistered / Unconfirmed GUEST, unregistred user! 2002-06-08 #4 roundTo( 1023.456,-2) 注意Use Math单元
I ili Unregistered / Unconfirmed GUEST, unregistred user! 2002-06-09 #6 简单算法: *100, +5, 取整, /100。 很简单~~~:)
方 方雁 Unregistered / Unconfirmed GUEST, unregistred user! 2002-06-10 #7 formatfloat('0.0',12.123456) 取一位小数 formatfloat('0.00',12.123456) 取二位小数