Monday, June 3, 2024
145
rated 0 times [  146] [ 1]  / answers: 1 / hits: 18260  / 11 Years ago, tue, march 26, 2013, 12:00:00

I am using the new method: Utilities.formatString()



In the Google Documentation is says it is similar to sprintf %-style.



I searched and read this article about sprintf in PHP.



I cannot seem to get this to work as intended. It is meant to pad this 8 character string with 4 leading zeros. I know there are other ways to do this, But I am trying to get a handle on this sprintf / formatString thing.



var noFormat = 12345678;
var formatted = Utilities.formatString(%012s, noFormat);


I expected the var formatted to be equal to 000012345678.
my debugger tell me that formatted = 0, or sometimes it throws an error..



I am confused.


More From » google-apps-script

 Answers
45

try it like this :



function xxx(){
var noFormat = '12345678'
var formatted = Utilities.formatString(%012d, noFormat);
Logger.log(formatted)
}


the different parameters that can be used are easy to find on the web, here is an example that explains how the argument must be evaluated in php but the usage is the same.



Logger result :



enter


[#79365] Sunday, March 24, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dayshadelaniej

Total Points: 668
Total Questions: 121
Total Answers: 121

Location: Sao Tome and Principe
Member since Wed, Dec 21, 2022
1 Year ago
;