Sign in to follow this  
Followers 0
Qualitybit

Confused while try to print formated Integer

3 posts in this topic

Hi folks,

I need to print Integers with a variable length of 1 to 9 digits with decimal points - and fail :rolleyes:

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]

Share this post


Link to post
Share on other sites



Hi folks,

I need to print Integers with a variable length of 1 to 9 digits with decimal points - and fail :rambo:

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

:rolleyes:


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

Share this post


Link to post
Share on other sites

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

:rolleyes:

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]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0