Solved

how to check precision and length of a long ??

Posted on 2003-11-11
449 Views
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
Question by:mrigank
• 3
• 2
• 2

LVL 5

Author Comment

ID: 9728986
one mistake .. the type is not long but float or double ...
:)
0

LVL 92

Expert Comment

ID: 9729052
Have a look at the BigInteger class it may be useful.
0

LVL 2

Accepted Solution

Tols earned 50 total points
ID: 9729055
You may convert it to string and then parse it as String.
0

LVL 92

Expert Comment

ID: 9729088
I actually meant to type BigDecimal :)
0

LVL 5

Author Comment

ID: 9729632
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

LVL 5

Author Comment

ID: 9729827
>> 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

LVL 2

Expert Comment

ID: 9730400
I'm glad to hear that :-)
0

Featured Post

Suggested Solutions

network + 7 73
JDeveloper 12c for 32 bit 4 35
JList custom Cell Renderer refresh 15 43
maven project error 5 21
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.