[Qt-interest] A way to test the number of digits after a decimal point?

Arnold Krille arnold at arnoldarts.de
Tue Mar 31 20:37:44 CEST 2009


On Tuesday 31 March 2009 18:14:39 Jesús Fernández wrote:
> What about using a QRegExp?
> QRegExp rx("(\\d+)\\.?(\\d*)");
> The second captured string will give you the digits after the decimal point
> if exists.

"after the decimal _point_" Please remember that not all countries use the 
point for decimals. :-)
If the string is already (local aware) validated to be a float number, the 
right thing is to strip all white spaces (yes, there are countries that use 
white space as thousands separator) and look whether there is a character in 
there that is not a digit. If there is one, the strings represents a floating 
point and the count of chars (which would then be digits) after the non-digit 
is the number of digits after the decimal separator.

Maybe that can be done in the above reg-exp but I am not that good at regexp 
to do that on the fly without documentation...

Have fun,

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090331/c0b64433/attachment.bin 


More information about the Qt-interest-old mailing list