【发布时间】:2013-02-22 12:11:41
【问题描述】:
我有以下代码来舍入货币
function MyRound(value :currency) : integer;
begin
if value > 0 then
result := Trunc(value + 0.5)
else
result := Trunc(value - 0.5);
end;
到目前为止它运行良好,我现在的问题是如果我想对像 999999989000.40 这样的货币进行舍入,它会给出负值,因为 Truc 采用 int 而 MyRound 也返回 int。
我可能的解决方案是将货币转换为字符串并在 . 之前获取字符串并将字符串转换回货币。这是一个正确的方法吗?我是 delpi 的新手,所以请帮帮我。
【问题讨论】:
-
使用 int64 代替整数?
-
你建议的解决方案是错误的,不会起作用,因为你的问题是32位溢出。
标签: delphi delphi-xe rounding truncation