[已解决]怎么判断小数点后的数字大小?
本帖最后由 痒痒 于 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
stringsplit
帮助有!! $count = GUICtrlRead($Input1) + GUICtrlRead($Input2) + GUICtrlRead($Input3)
$tempcount=StringSplit($count,".")
If Number($tempcount) < 10 Then
If Number($tempcount) > 5 Then
$count=$tempcount+1
ElseIf Number($tempcount) = 5 Then
$count=$tempcount&".5"
ElseIf Number($tempcount) < 5 Then
$count=$tempcount&"."&StringLeft($tempcount,1)
EndIf
Else
If Number($tempcount) > 50 Then
$count=$tempcount+1
ElseIf Number($tempcount) = 50 Then
$count=$tempcount&".5"
ElseIf Number($tempcount) < 50 Then
$count=$tempcount&"."&StringLeft($tempcount,1)
EndIf
EndIf
MsgBox(0,"",$count)不知道这段代码达到你的要求了没有。 不知道这段代码达到你的要求了没有。
lanfengc 发表于 2010-2-23 15:15 http://www.autoitx.com/images/common/back.gif
谢谢你的代码,辛苦了。
你写的判断里,三个inputbox相加后结果不对了。
input4里的结果是前面三个input相加。
主要是判断小数后面的数字大小,
例如:
1.1~1.4 转为 1.5。
1.5 还是 1.5。
1.51~2 转为 2 回复 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 > 5 Then
$a += 1
Return $a
ElseIf $a <= 5 Then
$a = 5
EndIf
Return $a & '.' & $a
EndFunc ;==>test 回复
afan 发表于 2010-2-23 15:41 http://www.autoitx.com/images/common/back.gif
afan,谢谢你的多次帮助。问题解决。
页:
[1]