Solved

how to check precision and length of a long ??

Posted on 2003-11-11
7
452 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap not working 8 60
maven module vs maven project 3 47
sql import cannot be resolved jsp 3 49
printf performancy 11 73
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

830 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