找回密码
 加入
搜索
查看: 4595|回复: 6

[AU3基础] [已解决]怎么判断小数点后的数字大小?

  [复制链接]
发表于 2010-2-23 09:18:21 | 显示全部楼层 |阅读模式
本帖最后由 痒痒 于 2010-2-23 15:47 编辑



如图,怎么判断“总数”栏内小数点后的数字大小并转换
“总数”的结果为上面三个inputbox内容相加所得。

例如:
1.1~1.4 转为 1.5。
1.5 还是 1.5。
1.51~2 转为 2。


附源码。
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 245, 219, 416, 581)
$Input1 = GUICtrlCreateInput("1", 64, 24, 153, 21)
$Input2 = GUICtrlCreateInput("1.14", 64, 56, 153, 21)
$Input3 = GUICtrlCreateInput("1.2", 64, 88, 153, 21)
$Input4 = GUICtrlCreateInput("", 64, 184, 153, 21)
$Button1 = GUICtrlCreateButton("计算", 55, 136, 123, 25)
$Label1 = GUICtrlCreateLabel("第一个", 24, 26, 40, 17)
$Label2 = GUICtrlCreateLabel("第二个", 24, 58, 40, 17)
$Label3 = GUICtrlCreateLabel("第三个", 24, 90, 40, 17)
$Label4 = GUICtrlCreateLabel("总  数", 24, 186, 37, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
        Case $GUI_EVENT_CLOSE
                Exit
                Case $Button1
                        Dim $count
                        $count = GUICtrlRead($Input1) + GUICtrlRead($Input2) + GUICtrlRead($Input3)
                        GUICtrlSetData($Input4, $count)


EndSwitch
WEnd

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-2-23 09:34:28 | 显示全部楼层
stringsplit
发表于 2010-2-23 10:13:04 | 显示全部楼层



帮助有!!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-2-23 15:15:11 | 显示全部楼层
$count = GUICtrlRead($Input1) + GUICtrlRead($Input2) + GUICtrlRead($Input3)
$tempcount=StringSplit($count,".")
If Number($tempcount[2]) < 10 Then
        If Number($tempcount[2]) > 5 Then
                $count=$tempcount[2]+1
        ElseIf Number($tempcount[2]) = 5 Then
                $count=$tempcount[2]&".5"
        ElseIf Number($tempcount[2]) < 5 Then
                $count=$tempcount[1]&"."&StringLeft($tempcount[2],1)
        EndIf
Else
        If Number($tempcount[2]) > 50 Then
                $count=$tempcount[2]+1
        ElseIf Number($tempcount[2]) = 50 Then
                $count=$tempcount[2]&".5"
        ElseIf Number($tempcount[2]) < 50 Then
                $count=$tempcount[1]&"."&StringLeft($tempcount[2],1)
        EndIf
EndIf
 MsgBox(0,"",$count)
不知道这段代码达到你的要求了没有。
 楼主| 发表于 2010-2-23 15:39:39 | 显示全部楼层
不知道这段代码达到你的要求了没有。
lanfengc 发表于 2010-2-23 15:15


谢谢你的代码,辛苦了。
你写的判断里,三个inputbox相加后结果不对了。
input4里的结果是前面三个input相加。
主要是判断小数后面的数字大小,
例如:
1.1~1.4 转为 1.5。
1.5 还是 1.5。
1.51~2 转为 2
发表于 2010-2-23 15:41:14 | 显示全部楼层
回复 5# 痒痒


    这意思?
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 245, 219, 416, 581)
$Input1 = GUICtrlCreateInput("1", 64, 24, 153, 21)
$Input2 = GUICtrlCreateInput("1.14", 64, 56, 153, 21)
$Input3 = GUICtrlCreateInput("1.2", 64, 88, 153, 21)
$Input4 = GUICtrlCreateInput("", 64, 184, 153, 21)
$Button1 = GUICtrlCreateButton("计算", 55, 136, 123, 25)
$Label1 = GUICtrlCreateLabel("第一个", 24, 26, 40, 17)
$Label2 = GUICtrlCreateLabel("第二个", 24, 58, 40, 17)
$Label3 = GUICtrlCreateLabel("第三个", 24, 90, 40, 17)
$Label4 = GUICtrlCreateLabel("总  数", 24, 186, 37, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $count = GUICtrlRead($Input1) + GUICtrlRead($Input2) + GUICtrlRead($Input3)
                        GUICtrlSetData($Input4, $count)
                        MsgBox(0, 0, test($count))
        EndSwitch
WEnd

Func test($n)
        $a = StringRegExp($n, '(\d+)\.(\d)', 3)
        If @error Then Return $n
        If $a[1] > 5 Then
                $a[0] += 1
                Return $a[0]
        ElseIf $a[1] <= 5 Then
                $a[1] = 5
        EndIf
        Return $a[0] & '.' & $a[1]
EndFunc   ;==>test

评分

参与人数 1金钱 +10 收起 理由
痒痒 + 10 谢谢你的多次帮助!你的正则太棒了

查看全部评分

 楼主| 发表于 2010-2-23 15:45:45 | 显示全部楼层
回复
afan 发表于 2010-2-23 15:41



    afan,谢谢你的多次帮助。问题解决。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-9 06:57 , Processed in 0.079581 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表