Qualitybit Posted June 30, 2007 Share Posted June 30, 2007 Hi folks, I need to print Integers with a variable length of 1 to 9 digits with decimal points - and fail Example: 1 -> 1 101 -> 101 12476 -> 12.476 324786120 -> 324.786.120 relevant advice would be appreciated :-) 101010 [font="Courier New"][center]Me vs. 127.0.0.1 =>> 0:2But I never give up! >:-][/center][/font] Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 30, 2007 Share Posted June 30, 2007 Hi folks, I need to print Integers with a variable length of 1 to 9 digits with decimal points - and fail I thought of StringFormat() right off, but it turned out to be a little more complex than that - which made it interesting. Came up with a function for it though: $string = "123456" $string = _Dot3($string) MsgBox(64, "Results", $string) Func _Dot3($sInput) Local $dots, $i, $sOutput = "" If StringLen($sInput) > 3 Then $iDots = Int(StringLen($sInput) / 3) $iModulus = Mod(StringLen($sInput), 3) If $iModulus Then $sOutput = StringLeft($sInput, $iModulus) & "." For $i = 0 To $iDots - 1 $sOutput &= StringMid($sInput, $iModulus + 1 + ($i * 3), 3) & "." Next $sOutput = StringTrimRight($sOutput, 1) Else Return $sInput EndIf Return $sOutput EndFunc ;==>_Dot3 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Qualitybit Posted June 30, 2007 Author Share Posted June 30, 2007 I thought of StringFormat() right off, but it turned out to be a little more complex than that - which made it interesting. Came up with a function for it though: $string = "123456" $string = _Dot3($string) MsgBox(64, "Results", $string) Func _Dot3($sInput) Local $dots, $i, $sOutput = "" If StringLen($sInput) > 3 Then $iDots = Int(StringLen($sInput) / 3) $iModulus = Mod(StringLen($sInput), 3) If $iModulus Then $sOutput = StringLeft($sInput, $iModulus) & "." For $i = 0 To $iDots - 1 $sOutput &= StringMid($sInput, $iModulus + 1 + ($i * 3), 3) & "." Next $sOutput = StringTrimRight($sOutput, 1) Else Return $sInput EndIf Return $sOutput EndFunc ;==>_Dot3 StringFormat was also my first thought. But I fail cause decimal points within integers are not supportet. thx this fullfill my needs. 10101 [font="Courier New"][center]Me vs. 127.0.0.1 =>> 0:2But I never give up! >:-][/center][/font] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now