要求支持负数!例如:21.333 保留两位小数四舍五入 21.33567.238 保留两位小数四舍五入 567.24-63.289 保留一位小数四舍五入 -63.3
请问这个函数如何写??????
另外:
round 函数是去除小数位并四舍五入 , 我记得好像有一个函数是去除小数位但不四舍五入
请问这个函数如何写??????
另外:
round 函数是去除小数位并四舍五入 , 我记得好像有一个函数是去除小数位但不四舍五入
调试欢乐多
你说的另一个函数是Int.
1.您的意思是不是要自己设定小数位?如果这样我不知道系统有没有函数不过可以自己写一个
founction myround(value:double;int:integer):double;
begin
result:= round(value*int*10)/(int*10);
end;
RoundTo(1.234, -2)=1.23在uses中加入Math
Rounds a floating-point value to a specified digit or power of ten using asymmetric arithmetic rounding.UnitMathCategoryArithmetic routinestype TSimpleRoundToRange = -37..37;
function SimpleRoundTo(const AValue: Double; const ADigit: TSimpleRoundToRange = -2): Double;DescriptionCall SimpleRoundTo to round AValue to a specified power of ten.AValue is the value to round.ADigit indicates the power of ten to which you want AValue rounded. It can be any value from –37 to 37 (inclusive).SimpleRoundTo uses asymmetric arithmetic rounding to determine how to round values that are exactly midway between the two values that have the desired number of significant digits. This method always rounds to the larger value.The following examples illustrate the use of SimpleRoundTo: Expression ValueSimpleRoundTo(1234567, 3) 1234000
SimpleRoundTo(1.234, -2) 1.23
SimpleRoundTo(1.235, -2) 1.24
SimpleRoundTo(-1.235, -2) -1.23
用的时候只需
uses Math;Expression ValueSimpleRoundTo(1234567, 3) 1234000
SimpleRoundTo(1.234, -2) 1.23
SimpleRoundTo(1.235, -2) 1.24
SimpleRoundTo(-1.235, -2) -1.23
Floor(x) 取小于或等于x的最大整数
Ceil(x) 取大于或等于x的最小整数