-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Kuljit wrote:
[snip]
Ask the user to enter a decimal/float number(eg. 32.8952), then count
the number of digits in that number after the decimal point(4 in this
case).
eg: If user enters 45.99420 then we should get 5, which are the number
of digits after the decimal point.
so i want to count the number of digits after the decimal point as i
have said in my quoted text. But instead of accepting it in a string, i
want to accept it in float datatype.
Unfortunately, if (as you say) you want to count the number of digits
after the decimal point in a /floating point number/ (and not a string),
then your examples are a bit out of whack.
Consider that the user enters the string "32.8952", and you convert it
to a floatingpoint number (your first example). There are clearly 4
significant digits following the decimal point. *But*, 32.8952 /as a
rational number/ is the same as 32.89520, which (by your second example)
you wish to count as 5 digits after the decimal point. /And/, the number
is the same as 32.895200, which is 6 decimal places (by extension of
your two examples).
Do you see the problem? Which interpretation of the number is correct
for your count?
Also, when working with /floatingpoint/ numbers, floatingpoint is
inaccurate: a number /entered/ as 45.99420 might actually become
45.994197827734 , which will have a different count of significant
decimal places than you expect
So, to satisfy your count requirement, you cannot count the digits in
the floatingpoint datatype.
- --
Lew Pitcher, IT Specialist, Corporate Technology Solutions,
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla -
http://enigmail.mozdev.org
iD8DBQFD/y9/agVFX4UWr64RAi9 eAJ4uhYQiboRiLl x6FjtRvS9sb8zGt wCfa81k
BMvnCHhESl8LOYm Rfeg0YeQ=
=Brvz
-----END PGP SIGNATURE-----