kylomas Posted September 10, 2012 Share Posted September 10, 2012 Hi, I am trying to format duration output as: nnnn.nnnn with 0 padding using stringformat. I cannot get digits before the decimal to o pad. Ive tried the following stringformat("%04.4f",round(timerdiff($time)/1000,4)) stringformat("%4.4f",round(timerdiff($time)/1000,4)) stringformat("%-4.4f",round(timerdiff($time)/1000,4)) stringformat("%-04.4f",round(timerdiff($time)/1000,4)) These all yield either n.nnnn or an error. Perhaps one of you "C" gurus who understand "sprintf" know whether or not this can be done with stringformat, and how. Alternatively, I'll put in code to determine the length of the lefthand part of the number and concatenate the correct number of zeros, a kludgy solution, at best. Thanks, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
AZJIO Posted September 10, 2012 Share Posted September 10, 2012 $time = 4.45 MsgBox(0, 'Yes?', stringformat("%0.4i.%.4i", $time, ($time - Int($time))*10000)) My other projects or all Link to comment Share on other sites More sharing options...
kylomas Posted September 10, 2012 Author Share Posted September 10, 2012 AZJIO, Thanks, was working on splitting the exponent from the mantissa and formatting each seperately. Your example does this nicely. I finally wound up with this func c_timer_output($str,$time) local $ttmp = round(timerdiff($time)/1000,4) local $a10 = stringsplit($ttmp,".") consolewrite("!> " & stringformat("%-50s", $str) & " = " & stringformat("%0.4i.%.4i",$a10[1],$a10[2]) & " seconds" & @lf) endfunc Even though it works, it seems like a goofy solution. Perhaps I'm being naive! kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
ProgAndy Posted September 10, 2012 Share Posted September 10, 2012 You have to count all characters for the minimum length. 4 digits + 1 decimal mark + 4 digits = 9 chars stringformat("%09.4f",round(timerdiff($time)/1000,4)) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
kylomas Posted September 10, 2012 Author Share Posted September 10, 2012 ProgAndy, Thanks, I suspected it was something I was missing!! kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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