小弟用D6+sqlserver开发数据库程序,有这样一张表,其中有一个float类型的字段;插入一条数据后,该字段显示的数据小数点后面足有十位之多;我想做这样的一个查询:只保留小数点后三位,并且要四舍五入,剩下的几位全部忽略不让它显示。
  我用round函数,虽然可以四舍五入,但其余几位全部以零显示出来。请各位大侠指点!

解决方案 »

  1.   

    使用过程:
      FloatToDecimal
      

  2.   

    FloatToDecimal procedure
    --------------------------------------------------------------------------------
    Converts a floating-point value to a decimal representation.UnitSysutilsCategoryfloating point conversion routinesprocedure FloatToDecimal(var DecVal: TFloatRec; const Value; ValueType: TFloatValue; Precision, Decimals: Integer);DescriptionFloatToDecimal converts a floating-point value to a decimal representation that is suited for further formatting. The Value parameter must be a variable of type Extended or Currency, as indicated by the ValueType parameter. For values of type Extended, the Precision parameter specifies the requested number of significant digits in the result--the allowed range is 1..18. For values of type Currency, the Precision parameter is ignored, and the implied precision of the conversion is 19 digits. The Decimals parameter specifies the requested maximum number of digits to the left of the decimal point in the result. Precision and Decimals together control how the result is rounded. To produce a result that always has a given number of significant digits regardless of the magnitude of the number, specify 9999 for the Decimals parameter.
      

  3.   

    只要双击Table控件,加入所有字段,并在相应的字段上设置属性DisplayFormat:='0.000'即可。
      

  4.   

    或者直接使用FormatFloat函数指定要显示的格式。
      

  5.   

    sql语句
    conver(numeric(10,3),floatfield)
    就可以了
      

  6.   

    在sqlserver中设置字段的小数点位数.