I want to "stringify" a number and add zero-padding, like how printf("%05d")
would add leading zeros if the number is less than 5 digits.
I want to "stringify" a number and add zero-padding, like how printf("%05d")
would add leading zeros if the number is less than 5 digits.
Use this:
5 here corresponds to 5 in
printf("%05d")
. 10 is the radix, you can put 16 to print the number in hex.QString QString::rightJustified ( int width, QChar fill = QLatin1Char( ' ' ), bool truncate = false ) const
result is now 00099
The Short Example:
Try:
EDIT: According to the docs at http://qt-project.org/doc/qt-4.8/qstring.html#sprintf:
Warning: We do not recommend using QString::sprintf() in new Qt code. Instead, consider using QTextStream or arg(), both of which support Unicode strings seamlessly and are type-safe. Here's an example that uses QTextStream:
Read the other docs for features missing from this method.
I was trying this (which does work, but cumbersome).
I use a technique since VB 5
I use this recursive function to pad zero!