Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

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.
0
mrigank
Asked:
mrigank
  • 3
  • 2
  • 2
1 Solution
 
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
 
TolsCommented:
You may convert it to string and then parse it as String.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now