Jump to content

Leading Zero


Recommended Posts

Try function StringFormat.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Developers

Yes it makes it a string as values never have leading zero's. So what are you trying to solve here?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

The internal representation of a number and the format when displaying this number are two different things (as they are in Excel as well).
Use StringFormat before you display the integer. This does not affect the internal representation.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

$d_Number = 6
$s_Number = StringRight("00" & $d_Number, StringLen($d_Number) > 2 ? StringLen($d_Number) : 2)
MsgBox(0,"", $s_Number)

$d_Number = 15
$s_Number = StringRight("00" & $d_Number, StringLen($d_Number) > 2 ? StringLen($d_Number) : 2)
MsgBox(0,"", $s_Number)

$d_Number = 115
$s_Number = StringRight("00" & $d_Number, StringLen($d_Number) > 2 ? StringLen($d_Number) : 2)
MsgBox(0,"", $s_Number)

 

Link to comment
Share on other sites

using StringFormat (as already suggested in post #2)

Local $iWantedDigits = 2 ; <-- choose wanted length

For $i = 0 To 15
    ConsoleWrite(_Leading0($iWantedDigits, $i) & @CRLF)
Next

; returns the passed number formatted
; with a length of $iNrDigits with leading zero
Func _Leading0($iNrDigits, $iNum)
    Return StringFormat('%0' & $iNrDigits & 's', $iNum)
EndFunc   ;==>_Leading0

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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