Jump to content

Recommended Posts

Posted

I need to format a number to 2 places left of the decimal (leaving the 0 for a single digit number). Everything in AutoIT seems to truncate the leading zero. Is there a simple way to pad my decimal number to two digits?

Here is my code:

#include <Date.au3>

; Julian date of today.

$sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)

; Formatting date

Dim $Y, $M, $D

$sJulDate = _DayValueToDate ($sJulDate, $Y, $M, $D)

MsgBox(4096, "", "In MMDD format:" & $M & $D)

I need $M and $D to display 2 digits instead of truncating the leading zero.

Thanks!

  • Developers
Posted

  aaronj said:

I need $M and $D to display 2 digits instead of truncating the leading zero.

<{POST_SNAPBACK}>

MsgBox(4096, "", "In MMDD format:" & StringFormat("%02i%02i",$M, $D))

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

Posted (edited)

#include <Date.au3>

Dim $Y, $M, $D

$sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)

$sJulDate = _DayValueToDate ($sJulDate, $Y, $M, $D)

If StringLen ($M) <> 2 Then
   $M = "0" & $M
EndIf  
If StringLen ($D) <> 2 Then
   $D = "0" & $D
EndIf 
MsgBox(4096, "", "In MMDD format:" & $M & $D)

Eg. If its the 12th of May, it will display "0512", if its the 5th of August, it will display "0805"

Edit: Dame you Jdeb! *Shakes fist. Jk, theres always seems to be a better way than mine lol.

Edited by Burrup

qq

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