关于Math.Floor的问题

zhourongbiao zhourongbiao 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面的程序输出什么内容?

procedure TForm1.btn1Click(Sender: TObject);
var
WLLatitudeFZ : double;
WLLatitudeI, WLLatitudeF : Integer;
begin
WLLatitudeFZ := 10.111;
WLLatitudeFZ := StrToFloat(Format('%.2f', [WLLatitudeFZ]));
WLLatitudeI:= Floor(WLLatitudeFZ);
WLLatitudeF:= Floor(Frac(WLLatitudeFZ) * 100);
ShowMessage(IntToStr(WLLatitudeF) + ',' + IntToStr(Floor(Frac(10.11)*100)));
end;

我预期结果是:11,11,因为WLLatitudeFZ=10.11
但是在Delphi7中的结果是:10,11,为什么?
WLLatitudeFZ := StrToFloat(Format('%.2f', [WLLatitudeFZ]));的本意在于只保持小数后两位,可是如果去掉这句话,结果就是11,11了,这又是为什么?
...全文

相关推荐

Java Math.round(),Math.ceil(),Math.floor()的区别详解

主要介绍了Java Math.round(),Math.ceil(),Math.floor()的区别详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

weixin_38663167

Math取整方法区别[可运行源码]

本文详细介绍了Math.round()、Math.ceil()和Math.floor()三种取整方法的区别。Math.round()实现四舍五入,但当小数点第一位为5时,正负数处理方式不同:正数进位,负数直接舍去。Math.ceil()为向上取整,小数部分直接舍去并向整数部分进1。Math.floor()为向下取整,直接舍去小数部分。文章还通过具体示例展示了不同方法的计算结果,并特别指出Math.floor()可能存在的精度问题,提醒读者谨慎使用。

生活碎片

JavaScript Math.floor方法(对数值向下取整)

主要介绍了Math.floor 方法用于对数值向下取整,即得到小于或等于该数值的最大整数,需要的朋友可以参考下

weixin_38621082

JavaScript中使用Math.floor()方法对数字取整

主要介绍了JavaScript中使用Math.floor()方法对数字取整,是JS入门学习中的基础知识,需要的朋友可以参考下

weixin_38743076

JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解

首先还是看看[removed] The Definitive Guide, 4th Edition中对三个函数的定义。 Math.ceil(): round a number up Arguments: Any numeric value or expression Returns: The closest integer greater than or equal to x. ———————————————————————————————– Math.floor(): round a number down Arguments: Any numeric value or expressi

weixin_38612568
评论 3
收藏 已收藏
分享
返回顶部