Solved

how to check precision and length of a long ??

Posted on 2003-11-11
7
451 Views
Last Modified: 2010-03-31
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
Comment
Question by:mrigank
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Author Comment

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

Expert Comment

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

Accepted Solution

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

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 92

Expert Comment

by:objects
ID: 9729088
I actually meant to type BigDecimal :)
0
 
LVL 5

Author Comment

by:mrigank
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

by:mrigank
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

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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
thymeleaf natural templating vs JSP 2 106
Java Options in Zimbra Server 2 55
split string containing \r\n in Java 46 44
throw exception 21 44
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)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question