设置一个const esp=1e-2
再设置一个判断语句

解决方案 »

  1.   

    Round(9.802 * 100) / 100
      

  2.   

    认真看看帮助后,你会惊愕地发现不论是Format还是Round都不是真正的“四舍五入”,而是“四舍六入五取双”。(真不知道现实中有多少Delphi写的软件犯了同样的错误)
      

  3.   

    帮助里面已经说得很清楚了,Round是四舍六入五取双function Round(X: Extended): Int64;DescriptionThe Round function rounds a real-type value to an integer-type value.X is a real-type expression. Round returns an Int64 value that is the value of X rounded to the nearest whole number.{ **************If X is exactly halfway between two whole numbers, the result is always the even number.***********} This method of rounding is often called 揃anker抯 Rounding?If the rounded value of X is not within the Int64 range, a run-time error is generated, which can be handled using the EInvalidOp exception.Note: The behavior of Round can be affected by the Set8087CW procedure or SetRoundMode function.
      

  4.   

    可以用ShowNum(Num:Double;Precision:Integer):String;函数
    前一参数是原来的实数,后一参数是你要保留的位数,比如:1、2、3
    随心所欲,轻松搞掂~~~~~~~~~~~~~