xx3fb 发表于 2009-6-12 12:24:52

如何把0.1输出成0.10?关于小数的问题,内有代码请进来看下

新手问题,我用如下的代码想实现把小数0.1,0.2,0.3 send()成0.10,0.20,0.30 ;0.15,0.25,0.35原样输出,但是不行。
结果有些不能输出
代码如下:

Run("notepad.exe")
WinActivate ( "无标题 - 记事本" )
$e=0
Do
outp()
$e+=1
Until $e=20

FUNC outp ()
       
        $x1=0.2+Round((Random()*0.2/0.05),0)*0.05                                                                        ;0.2+INT(RAND()*0.2/0.05)*0.05
        $x2=0.1+Round(Random()*0.2/0.05,0)*0.05       
        $x3=Round(Random()*0.1/0.05,0)*0.05       

        Send($x1)
       
        send("{Tab}")
       
           Send($x2)
       
        send("{Tab}")
       
           Send($x3)
       
        send("{Tab}")
          
        Sendt($x1)
       
        send("{Tab}")
       
        Sendt($x2)
       
        send("{Tab}")
          
        Sendt($x3)
       
        send("{Tab}{Enter}")


       
EndFunc

func Sendt($s);<===这个函数似乎有问题 但是没有发现什么问题;请高手指点!
       
        if $s=0 Then
                send("0.00")
        else

                If mod($s, 0.1) = 0.05 Then
                        send($s)

                        Elseif mod($s, 0.1) = 0 Then
                        send($s)
                        send("0")
       
                EndIf
        EndIf
EndFunc

xx3fb 发表于 2009-6-12 12:30:10

func Sendt($s)
       
        if $s==0 Then
                send("0.00")
        else

                If mod($s, 0.1) == 0.05 Then
                        send($s)

                        Elseif mod($s, 0.1) == 0 Then
                        send($s)
                        send("0")
       
                EndIf
        EndIf
EndFunc

xx3fb 发表于 2009-6-12 12:35:24

解决了,==

kn007 发表于 2009-6-12 14:40:58

留个名。。。

大绯狼 发表于 2009-6-13 18:55:13

StringFormat("%.2f","0.1")
页: [1]
查看完整版本: 如何把0.1输出成0.10?关于小数的问题,内有代码请进来看下