PDA

View Full Version : how to format a number into a const width string ?



lovelypp
25th July 2008, 09:17
How to format a number into a const width string ?
For example, if n is 12345, it is formatted to "12345", if n is 123, it is formated to "00123", if n is 0, it is formatted to "00000".
thanks!

muellerp
25th July 2008, 10:38
QString new( QString( "00000%1" ).arg( 1234 ) );
new = new.right( 5 );

Others may find more efficient solutions

jpn
25th July 2008, 10:56
Take a look at 'fieldWidth' and 'fillChar' parameters of QString::arg().

elcuco
25th July 2008, 22:45
QString new( QString( "00000%1" ).arg( 1234 ) );
new = new.right( 5 );

Others may find more efficient solutions

that will not compile... "new" is a keyword ;-)