2010-08-03 58 views

回答

0

例如:


class DOBLE 

creation 
    make 

feature 
    make is 
     local 
      n: DOUBLE 
      output: STRING 
     do 
      n := 118.1999999999999 
      output := n.to_string_format(2) -- 2 digits in fractionnal part 
      std_output.put_string(output + "%N") 
     end 
end 
2

您应该使用类FORMAT_DOUBLE

local 
    fd: FORMAT_DOUBLE 
do 
    create fd.make (5, 3) 
    print (fd.formatted ({REAL_64} 12345.6789)) --> "12345.679" 
    print (fd.formatted ({REAL_64} 12345.6)) --> "12345.600" 
    print (fd.formatted ({REAL_64} 0.6)) --> "0.600" 

    create fd.make (10, 2) 
    fd.right_justify 
    print (fd.formatted ({REAL_64} 1.678)) --> "  1.68" 

    create fd.make (20, 3) 
    fd.right_justify 
    print ("[" + fd.formatted ({REAL_64} 12345.6789) + "]%N") --> [   12345.679] 
    fd.left_justify 
    print ("[" + fd.formatted ({REAL_64} 12345.6789) + "]%N") --> [12345.679   ] 
    fd.center_justify 
    print ("[" + fd.formatted ({REAL_64} 12345.6789) + "]%N") --> [  12345.679  ] 

等等......

还有一组类模仿的 “printf”你可以在http://www.amalasoft.com/downloads.htm 找到他们我没有使用他们自己,但这可能会满足您的需求。

这是通过使用ECMA艾菲尔(我不知道在哪里,从之前的响应来了,但双不具备这样的功能`to_string_format”和DOUBLE是REAL_64

老字号