Timo Posted October 22, 2006 Posted October 22, 2006 Hi, I need your help. I have a number in the format "4.160,00" and I want to convert it to "4160" or "4160.00". I've studied the help (StringFormat), but I didn't find a solution... Can someone help me please? Bye, Timo Bye...,Timo
this-is-me Posted October 22, 2006 Posted October 22, 2006 Read again under "Precision Specification". Who else would I be?
Timo Posted October 22, 2006 Author Posted October 22, 2006 Can you please give me an example? My English ist not the best, I tried but but I did not get it to work. It would be very nice if you could help me. Thanks, Timo Bye...,Timo
jvanegmond Posted October 22, 2006 Posted October 22, 2006 $sString = "4.160,00" $sString = StringReplace($sString,".","") $sSplit = StringSplit($sString,",") $sString = $sSplit[1] MsgBox(0, "", $sString) github.com/jvanegmond
Timo Posted October 22, 2006 Author Posted October 22, 2006 Many thanks Manadar. Good idea, much easier than StringFormat. But what about SF? Is this not possible with it? Bye...,Timo
this-is-me Posted October 22, 2006 Posted October 22, 2006 Another (possibly more politically correct) way to do this: MsgBox(0,"",Number("4.160,00") * 1000) Who else would I be?
Moderators SmOke_N Posted October 22, 2006 Moderators Posted October 22, 2006 Let's all join in the fun:MsgBox(0, '', _Convert("4.160,00")) Func _Convert($sText) Return StringReplace(StringReplace($sText, '.', ''), ',', '.') EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
xcal Posted October 22, 2006 Posted October 22, 2006 I want to play too! $string = '4.160,00' $result_1 = StringSplit($string, '') MsgBox(0, '1', $result_1[1] & $result_1[3] & $result_1[4] & $result_1[5]) $result_2 = StringReplace(StringLeft($string, 5), '.', '') MsgBox(0, '2', $result_2) How To Ask Questions The Smart Way
Moderators SmOke_N Posted October 22, 2006 Moderators Posted October 22, 2006 Continued...MsgBox(0, '', _Convert("4.160,00")) Func _Convert($sText) Local $sHold, $sMid For $iCC = 1 To StringLen($sText) $sMid = StringMid($sText, $iCC, 1) If $sMid <> '.' And $sMid <> ',' Then $sHold &= $sMid If $sMid = ',' Then $sHold &= '.' Next Return $sHold EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
GaryFrost Posted October 22, 2006 Posted October 22, 2006 Informational for those of you who wish to add commas into numbersoldy so probably can be done with less code nowhttp://www.autoitscript.com/forum/index.ph...ost&p=87193 SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
this-is-me Posted October 22, 2006 Posted October 22, 2006 ROFL It is amazing how many methods of achieving the same goal can be imagined by a group of people. Who else would I be?
Moderators SmOke_N Posted October 22, 2006 Moderators Posted October 22, 2006 (edited) gafrost said: Informational for those of you who wish to add commas into numbers oldy so probably can be done with less code now http://www.autoitscript.com/forum/index.ph...ost&p=87193Here's a go at it. Func _StrAddComma($sStr, $sSeperator = ',', $sEnd = '.') If $sSeperator = -1 Or $sSeperator = Default Then $sSeperator = ',' If $sEnd = -1 Or $sEnd = Default Then $sEnd = '.' Local $aNum = StringSplit($sStr, $sEnd), $nHold, $aSRE, $bUB, $iAdd If UBound($aNum) > 2 Then $aSRE = StringRegExp($aNum[1], '(\d+)(\d{3})', 3) $bUB = True Else $aSRE = StringRegExp($sStr, '(\d+)(\d{3})', 3) EndIf If UBound($aSRE) = 2 Then While IsArray($aSRE) $nHold = $sSeperator & $aSRE[1] & $nHold $aSRE = StringRegExp($aSRE[0], '(\d+)(\d{3})', 3) $iAdd += 1 WEnd EndIf If $bUB And $nHold Then Return StringTrimRight($sStr, $iAdd * 3) & $nHold & $sEnd & $aNum[2] ElseIf $nHold Then Return StringTrimRight($sStr, $iAdd * 3) & $nHold EndIf Return SetError(1, 0, $sStr) EndFunc Edit: Pasted the wrong version. Edit2: Fixed a but I noticed. Edit3: Put it in scripts in scraps and shortened it to 22 lines: http://www.autoitscript.com/forum/index.ph...st&p=255542 Edit4: Fixed a bug that xcal noticed ... thanks. Edited October 22, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
xcal Posted October 22, 2006 Posted October 22, 2006 (edited) It seems to stop working at 9223372036854775808. It works at 9223372036854775807. Don't ask how I know. edit - numbers reversed Edited October 22, 2006 by xcal How To Ask Questions The Smart Way
Moderators SmOke_N Posted October 22, 2006 Moderators Posted October 22, 2006 xcal said: It seems to stop working at 9223372036854775808. It works at 9223372036854775807. Don't ask how I know. edit - numbers reversedI had $iAdd = 1 Going to fix it now. MsgBox(64, '', _StrAddComma('9223372036854775808')) MsgBox(64, '', _StrAddComma('9223372036854775807')) Func _StrAddComma($sStr, $sSeperator = ',', $sEnd = '.') If $sSeperator = -1 Or $sSeperator = Default Then $sSeperator = ',' If $sEnd = -1 Or $sEnd = Default Then $sEnd = '.' Local $aNum = StringSplit($sStr, $sEnd), $nHold, $aSRE, $bUB, $iAdd If UBound($aNum) > 2 Then $aSRE = StringRegExp($aNum[1], '(\d+)(\d{3})', 3) $bUB = True Else $aSRE = StringRegExp($sStr, '(\d+)(\d{3})', 3) EndIf If UBound($aSRE) = 2 Then While IsArray($aSRE) $nHold = $sSeperator & $aSRE[1] & $nHold $aSRE = StringRegExp($aSRE[0], '(\d+)(\d{3})', 3) $iAdd += 1 WEnd EndIf If $bUB And $nHold Then Return StringTrimRight($sStr, $iAdd * 3) & $nHold & $sEnd & $aNum[2] ElseIf $nHold Then Return StringTrimRight($sStr, $iAdd * 3) & $nHold EndIf Return SetError(1, 0, $sStr) EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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