how to check precision and length of a long ??

Hi

I have a long data type. Along with it I have the maximum allowed length and the maximum allowed precision for the field. I want to check if the given number is within the required specifications.

Something like
boolean result = checkPrecision(longNumber, length, precision);

for example for length 4 and precision 2 the maximum value allowed is 99.99 ...
I want to make a generic method to which i can pass the length and precision and get the maximum allowed range ..

Can you help me out.
Thanks,
Mrigank.
LVL 5
mrigankAsked:
Who is Participating?
 
TolsConnect With a Mentor Commented:
You may convert it to string and then parse it as String.
0
 
mrigankAuthor Commented:
one mistake .. the type is not long but float or double ...
:)
0
 
objectsCommented:
Have a look at the BigInteger class it may be useful.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
objectsCommented:
I actually meant to type BigDecimal :)
0
 
mrigankAuthor Commented:
Actually my problem is that given a length and a precision how do i decide the maximum possible value of a number ..

like if i have 4,2 i have to return 99.99 as the maximum possible value ....
0
 
mrigankAuthor Commented:
>> You may convert it to string and then parse it as String.

Actually i got the max value as a string by appending nines to a string buffer and then converted it back to a Double. Just the opposite ;) ... but your suggestion gave me the idea .. :) ....
0
 
TolsCommented:
I'm glad to hear that :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.