[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: Re: kdeedu/kstars/kstars [POSSIBLY UNSAFE]
From: Malte Starostik <malte () kde ! org>
Date: 2003-09-25 5:02:52
[Download RAW message or body]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thursday 25 September 2003 06:53, Jason Harris wrote:
> CVS commit by harris:
>
> dmsBoxes now pad their fields with a leading "0" when the
> degree/minute/second values are less than 10.
>
> Sorry about the sprintf(), but it's by far the easiest way to prefix a "0"
> on a two-digit integer field when the value is less than 10. I mean, it's
> the difference between:
>
> QString s = QString().sprintf( "%02d %02d %02d", v1, v2, v3 );
>
> and:
>
> QString s1 = QString( "%1" ).arg( v1, 2 );
> if ( v1 < 10 ) { s1 = QString( "0%1" ).arg( v1, 1 ); }
> QString s2 = QString( "%1" ).arg( v2, 2 );
> if ( v2 < 10 ) { s2 = QString( "0%1" ).arg( v2, 1 ); }
> QString s3 = QString( "%1" ).arg( v3, 2 );
> if ( v3 < 10 ) { s3 = QString( "0%1" ).arg( v3, 1 ); }
> QString s = QString( "%1 %2 %3" ).arg( s1 ).arg( s2 ).arg( s3 );
>
> IOW, a no-brainer. If anyone knows a better way, let me know. :)
Depends on your personal definition of better:
QString s = QString::number( v1 + 100 ).right( 2 ) + " " + ...
Still longer than sprintf() of course; IMHO the Right Way would be to request
this feature from Trolltech as zero-padding is a very frequently needed
formatting option.
Regards,
- -Malte
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQE/cnb+VDF3RdLzx4cRAm81AJ9IkTnvuW+lxgRtAqZlL3gTjF0gXACgim7P
CUCm6gFy9nbuZihuvHXMt9M=
=Ksaa
-----END PGP SIGNATURE-----
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic