Jump to content

UDF: _PadZero()


FuryCell
 Share

Recommended Posts

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 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

Very nice.

<{POST_SNAPBACK}>

Thanks for the feedback. :evil:

It also removes padding if there is too much :D 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

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 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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...