Question

How to represent an Oracle decimal number with precision to a Java type properly?

Asked by: _Esam

Hi I have a Oracle table as follows:

CREATE TABLE FMS.FUND_NAV
  (FUND_ID NUMBER(10, 0) NOT NULL,
   TRADE_DATE DATE NOT NULL,
   NET_ASSET_VALUE NUMBER(17, 6) NULL,
   RATE NUMBER(12, 10) NULL,)

Now I created a Java bean for this record with the field types as follows:

public class FundNav{

    private int fldFundId = 0;
    private Date fldTradeDate = null;
    private double fldNetAssetValue = 0;
    private double fldRate = 0;

}

Here is my question?

In the table the fields:

NET_ASSET_VALUE NUMBER(17, 6)
RATE NUMBER(12, 10)  are Nubmers with the given precision i.e. (17,6) and (12,10)

Is is OK?
I don't think so ?

Because when I printed the results, I got one of the RATE as 9.4104E-5

How could I get them the way they are in the table? i.e. like 22.1234567890 ? instead of something
like 9.4104E-5 ???

Should I change the variable types in the bean? to what?

Should I change the double to BigDecimal, then How I get the values???
Please let me know.

THanks.
Esam.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-06-12 at 14:24:34ID22629755
Tags

oracle

,

decimal

,

number

,

precision

Topic

Java Standard Edition

Participating Experts
3
Points
125
Comments
25

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. oracle
    i want to build my career in ORACLE, but at the same time i want a good front end. So tell me is DEVELOPER strong enough to harness the full power of ORACLE or should i know how to access ORACLE with VB. also if u can recommend some great books on DEVELOPER/ORACLE FORMS AND ...
  2. Using OLAP and BI Beans
    Hi, My query is,i need to make use of Oracle's OLAP services and BI Beans for cretaing reports. As i am new to these two i would like to know how to go about it and the requirements for using OLAP and BI Beans.? Thanks
  3. Oracle Forms with Java Bean
    Dear Friends, There is a Bean Area component in Oracle Form.How we will use it in Oracle Form. Please give the complete process i.e. how will create bean , how will use in Form, what parameters should set. It urgent please send asap.
  4. Calling Java beans in Oracle Forms 6i
    I want to call a Java bean in Oracle Forms 6i, If anyone knows the procedure please help me out.
  5. using a bean to reteive results from oracle
    Hello, Now that I know how to get the data base results with <sql:> tags what more would I need to do to take advantage of a bean to get the results from oracle? thanks, Don

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: objectsPosted on 2007-06-12 at 16:31:32ID: 19270788

 

by: _EsamPosted on 2007-06-12 at 17:34:50ID: 19271048

Hi Objects,
I know what you tried to say by the link...
But that's not quite the problem.........

The real problem is the value itself.
I know you answered a question similar to this one but that wasn't pertinent to this one...

I will use the value in the calculations (mostly multiplications)...
I have a few variables that will hold decimals with differing precision and I will use them to calculate
a value and return the value with differing precison...

Do YOU THINK I SHOULD USE BigDecimal for my varialbes so that the calculating variable can have differing precision and the calculated variable can return an arbitrary precision ????????????

Please let me know...

Thanks and regards.
_Esam

 

by: objectsPosted on 2007-06-12 at 17:43:28ID: 19271073

the value is fine, its just how the result is diplayed that is your problem

 

by: objectsPosted on 2007-06-12 at 17:51:14ID: 19271092

double gives you ~ 15 significant digits
if u need to be more exact than that then go to BigDecimal

 

by: _EsamPosted on 2007-06-12 at 18:11:55ID: 19271150

Let me get  clarified then..

If I have
  rate = 12.123456789012 (14,12)
  factor = 1.1234567 (8,7)

Now if I want a result as: result = 12.123456 (8,6)

What type of varialbes should I use for rate, factor, and result  ? (What would be best calculation wise) ? (rate and factor are bean variables)

Yes, I will need to make sure that I return the variable result with six (6) digits after the decimal (two before decimal). --- because I will need to use this result to set the value in another column (of a table)
that expect it thus . . i.e. a number as (8,6)

Now value is more important than display (as thought in previous comment).

Please let me know...

Regards.
_Esam...

 

by: objectsPosted on 2007-06-12 at 18:18:06ID: 19271167

if you want the resulting value to be *exactly* that then you have to use BigDecimal

 

by: _EsamPosted on 2007-06-12 at 18:23:00ID: 19271181

Should I use BigDecimal for all my variables ... rate, factor and result ?
Or just the result (this is returning exactly as (8,6)) ?

If I am using only result as BigDecimal, then can my rate and factor stay as double ?

Thanks.
_Esam./

 

by: objectsPosted on 2007-06-12 at 18:25:17ID: 19271188

depends on what value you need to be exact.

 

by: _EsamPosted on 2007-06-12 at 18:34:07ID: 19271220

>>depends on what value you need to be exact.
Not clear about this?

Because this is what I wanted::
If I have
  rate = 12.123456789012 (14,12)
  factor = 1.1234567 (8,7)

Now if I want a result as: result = 12.123456 (8,6)  which is rate*factor

What type of variables should rate, factor and result be?

Thanks.
_Esam.

 

by: objectsPosted on 2007-06-12 at 18:41:32ID: 19271241

any decimal value you want to be exact you need to use BigDecimal, what aren't u clear about exactly?

 

by: _EsamPosted on 2007-06-12 at 19:05:37ID: 19271313

Sorry to be cryptic...

If I have a method as:

public ? getResult (? rate, ? factor){
 ?  result        
  result = rate*factor;
return result;
}

Here in the method, I am passing the rate and factor from two data bean(s).
And returning a result that I will use to update a table record in the database.

Now, in the tables of the database...
I have rate as: 12.123456789012 (14,12)
 factor as: 1.1234567 (8,7)

and the resulting value as: 12.123456 (8,6)

So, what type of variables should I use for my bean(s) to represent rate, and factor ?
What variable shoud my result be (if I want exacly as (8,6) ?

Hope I am clear ..

Thanks.
_Esam.

 

by: objectsPosted on 2007-06-12 at 19:16:22ID: 19271349

I can't answer that question, its your decision :)

> What variable shoud my result be (if I want exacly as (8,6) ?

but whats the point of having the result value exactly 8.6 if the value you use to calculate it are approximations.

 

by: _EsamPosted on 2007-06-12 at 19:34:14ID: 19271471

Well,
I will use this result to add to a value in a database table that has the format at (8,6) being Oracle Number.

Now say, if I had rate as : 12.123456789012 (14,12) and
 factor as: 1.1234567 (8,7) both being double(s)

And I got the result as: resiult = rate*factor

Can I assume that I can add this result (result) to the database table column having the format as (8,6)

Because I haven't tested how rate*factor would return if all were double(s).

It's not that I want exactly (8,6) .. but I want to make sure that if I had to inert a result that I insert it as
having the value (8,6)

Am I clear ?

Let me know...

Regards,
_Esam.

 

by: objectsPosted on 2007-06-12 at 19:41:59ID: 19271507

> 12.123456789012 (14,12)

if its a double then its *not* exactly 14,12
similiar for factor

> but I want to make sure that if I had to inert a result that I insert it as
having the value (8,6)

if thats the db column type then how would it store it as anything other than 8,6

 

by: _EsamPosted on 2007-06-12 at 19:57:31ID: 19271582


>>>
> 12.123456789012 (14,12)

if its a double then its *not* exactly 14,12
similiar for factor

How's that so?

>>if thats the db column type then how would it store it as anything other than 8,6
That's exactly what I was trying to understand.

Then I must make sure that the db column type matches the value I pass to use and that's why I needed
to make sure that the result I get is as (8,6) in terms of value at the end (extracted from precision).

Because depending on the value of rate*factor , the result could be ?

And I wanted to make sure at the end the value of result is as (8,6)
The result might have some different precision in between...

Please follow this post and let me know the Qs I had...

Thanks.
_Esam

 

by: objectsPosted on 2007-06-12 at 20:01:17ID: 19271590

> How's that so?

floating point numbers are an approximation by definition.

 

by: _EsamPosted on 2007-06-12 at 20:35:15ID: 19271798

>>floating point numbers are an approximation by definition.
To my understanding .. any type is an approximation..

But this is not the isseu...here...
issue here is how best to get the value(s)...

Becasue if I wanted to have a value with precision of at least 12 after the decimal the I should not use
float, I should at leaset use double...

Let me get this clear...

If I have a BigDecimal as 12.123456789012 ....
Then if I need to use a value as 12.123456 from this BigDecimal as float what I do???

That's the q ?

Thanks.
_Esam

 

by: objectsPosted on 2007-06-12 at 21:33:45ID: 19272135

float f = bd.floatValue();

but then you're back to an approximation

 

by: objectsPosted on 2007-06-12 at 22:04:29ID: 19272229

 

by: StillUnAwarePosted on 2007-06-17 at 09:23:44ID: 19302664

Just a though:

  If You want to get the greatest possible precission, You should use BigDecimal, the only drawback for doing that, may be the greater resource (memory and time) usage while calculating the result. If the latter is not the problem, why just not use the BigDecimal type?

 

by: mayflower8Posted on 2007-06-25 at 16:04:41ID: 19359902

 

by: _EsamPosted on 2007-07-04 at 17:39:09ID: 19421204

All comes to this point again:
If I have double(s)
 double  rate = 12.123456789012 (14,12)
  double factor = 1.1234567 (8,7)

Now if I want a result as: double result = 12.123456 (8,6)

Since double is giving me precision for 15-16 so I am fine with the result.
Now to put the result back to another table column I would like to have it as (8,6) - total 8 digits, 6 after decimal.

Now I really don't need to worry about BigDecimal at this point as I understand or not?

I just want the result with some rounding mechanism to 6 digits after the decimal !

How I do that?

Thanks.
_Esam.


 

by: objectsPosted on 2007-07-04 at 17:48:03ID: 19421227

if your database is storing it as 8.6 then thats what its going to store isn't it :)
or you can use what I originally suggested to convert it to a string with two decimal paces.

 

by: objectsPosted on 2007-07-04 at 17:52:17ID: 19421239

 

by: mayflower8Posted on 2007-07-07 at 19:28:57ID: 19439016

Have you looked at the link I gave you? I thought that could give you some ideas.
Take a look at the actual value that are stored in your oracle table. I assume they contain the correct values.
If you only want to print out your values, you can do one of the following ways:
Format your double value to the precision you want in your Java print statement.
http://forum.java.sun.com/thread.jspa?threadID=636919&messageID=3717655
or look at the thread I sent you earlier to use BigDecimal.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...