Solved

how to check precision and length of a long ??

Posted on 2003-11-11
7
454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

622 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