#856 closed Bug (Completed)
_StringAddThousandsSep() prefixes some #'s with ,
Reported by: | Ascendant | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Component: | AutoIt |
Version: | 3.3.0.0 | Severity: | None |
Keywords: | _StringAddThousandsSep | Cc: |
Description
During testing, this UDF sometimes puts a ',' at the beginning of a number which isn't correct. For example, the below results in -,123,456,789,012,345.67890:
#include <String.au3> MsgBox(16,"_StringAddThousandsSep() faulty reult", _ "Result of _StringAddThousandsSep('-123456789012345.67890'): "& _ _StringAddThousandsSep('-123456789012345.67890'))
_DebugBugReportEnv() Result:
Environment = 3.3.0.0 under WIN_XP/Service Pack 3 X86
Attachments (0)
Change History (3)
comment:1 Changed 16 years ago by Gary
- Resolution set to Completed
- Status changed from new to closed
comment:2 Changed 16 years ago by TicketCleanup
- Milestone set to Future Release
Automatic ticket cleanup.
comment:3 Changed 16 years ago by Spiff59
This version, incorporates the fix required above, and also strips off leading zeros, as returning a string such as "00,000,015,746" seems improper. This version is also more than twice as fast as the exisitng one. It retains all functionality, but will return @error = 1 if an invalid string is passed to the function. Presently, the first non-numeric character passed is replaced by a decimal point, and the passed string is truncated at the second non-numeric character. Rather than that "unpredictable" or undocumented behavior, I would think an @error code would be preferable.
{{{Func StringAddThousandsSep($sText, $Sep = ',', $Dec = '.')
If Not StringIsInt($sText) And Not StringIsFloat($sText) Then Return SetError(1)
Local $aSplit = StringSplit($sText, "-" & $Dec )
Local $iInt = 1
Local $iMod
If Not $aSplit[1] Then
$aSplit[1] = "-"
$iInt = 2
EndIf
If $aSplit[0] > $iInt Then
EndIf
$iMod = Mod(StringLen($aSplit[$iInt]), 3)
If Not $iMod Then $iMod = 3
$aSplit[$iInt] = StringRegExpReplace($aSplit[$iInt], '(?<=\d{' & $iMod & '})(\d{3})', $Sep & '\1')
For $i = 2 to $aSplit[0]
$aSplit[1] &= $aSplit[$i]
Next
Return $aSplit[1]
EndFunc
}}}
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
This was fixed after the release version. Should be in next beta.