FuryCell Posted June 28, 2005 Share Posted June 28, 2005 (edited) Here is a UDF i just made to pad a number with zeros.for example if you did:_PadZero(-3.14,2)it would return 03.14.it also knows when a number has enough places already._PadZero(003.14,3)would return 003.14 and it works with floats and negative numbers too.Useful for when you have to display numbers and want to always have the same amount of places.Here is the header.CODE;===============================================================================;; Function Name: _PadZero(); Description: Pads a number with zeros on the left side to the specified places; Syntax: _PadZero($vNumber, $iPlaces = 1); Parameter(s): $vNumber = Number to pad with zeros; $iPlaces = Number of place(s) to pad with zero(s); Requirement(s): None; Return Value(s): On Success - Returns a string representation of the number specified in $vNumber padded with zeros if necessary; On Failure - Returns "" and set @Error; @Error=1 $vNumber is not a valid number; @Error=2 $iPlaces is not a valid integer;; Author(s): SolidSnake <MetalGX91 at GMail dot com>; Note(s): If the number already has the more than or the same number of places specified by $iPlaces it will return the number.; This function works on both integers and floats;;===============================================================================Edit:updated header to reflect my new email address. (Previous Downloads 31)PZExample.au3 Edited December 11, 2006 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted June 28, 2005 Share Posted June 28, 2005 Very nice. It also removes padding if there is too much I like it! Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
FuryCell Posted June 28, 2005 Author Share Posted June 28, 2005 Very nice.<{POST_SNAPBACK}>Thanks for the feedback. It also removes padding if there is too much I like it!<{POST_SNAPBACK}>I was planning to put that feature in. It's already in??? HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted June 28, 2005 Share Posted June 28, 2005 _PadZero("0003.14", 2) I think you're the first person I've met that put a feature into a function and didn't realize it Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
jpm Posted June 28, 2005 Share Posted June 28, 2005 You already have a function in AutoIT it is StringFormat $n=12.34 $s=StringFormat("'%010.3f'",$n) MsgBox(0,"zeropadding",$s) Link to comment Share on other sites More sharing options...
FuryCell Posted June 28, 2005 Author Share Posted June 28, 2005 (edited) You already have a function in AutoIT it is StringFormat$n=12.34 $s=StringFormat("'%010.3f'",$n) MsgBox(0,"zeropadding",$s) <{POST_SNAPBACK}>Oops. Sorry i did not realize that. :">Thanks. Edited June 28, 2005 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
jpm Posted June 28, 2005 Share Posted June 28, 2005 Oops. Sorry i did not realize that. :">Thanks.<{POST_SNAPBACK}>it is a very powerful function for formating numbers 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