Jump to content

Recommended Posts

Posted (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 by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Posted

_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())
Posted

You already have a function in AutoIT it is StringFormat

$n=12.34
$s=StringFormat("'%010.3f'",$n)
MsgBox(0,"zeropadding",$s)
:)
Posted (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 by SolidSnake
HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
Posted

Oops. Sorry i did not realize that.  :">

Thanks.

<{POST_SNAPBACK}>

it is a very powerful function for formating numbers :)

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
  • Recently Browsing   0 members

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