Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sprintf() for JavaScript that behaves like Python's format (%)? [duplicate]

I need a JavaScript function (or jQuery plugin) for printf/sprintf. It needs to support named arguments ("%(foo)s") and padding ("%02d"), i.e. the following format string should work:

"%(amount)s.%(subunits)02d"

It only needs to support s and d, I don't care about all the other format strings (e.g. f, x, etc.). I don't need padding for strings/s, just d, I only need simple padding for d, e.g. %2d, %3d, %04d, etc.

like image 630
Amandasaurus Avatar asked Feb 24 '23 12:02

Amandasaurus


1 Answers

A previous question "Javascript printf/string.format" has some good information.

Also, dive.into.javascript() has a page about sprintf().

like image 140
diEcho Avatar answered Apr 25 '23 18:04

diEcho