newbie
newbie

Reputation: 1980

Fetching large value from the database

Sorry for this noob question but I really don't know what to search and how to solve it.I have a table structure like this:

enter image description here

This is only a part of my table.

budget_cost has 1000000000.1 literal

I tried to fetch the values

while( result.next() )
{
   ProjectBean projectBean = new ProjectBean();
   ...
   projectBean.setBudgetCost( result.getDouble( "budget_cost" ) );
   ...
}

my model has setter and getter of each variables

public class ProjectBean
{
    ...
    private double profitRate;
    private double vatRate;
    private double fees;
    private double budgetCost;
    private String dateDeadline;
    ...
}

I tried to print the budgetCost and it prints 1.0E9

I need it to display 1000000000.1 what am I doing wrong?

Upvotes: 1

Views: 48

Answers (1)

piet.t
piet.t

Reputation: 11911

Addressing your question: take a look at the class java.lang.DecimalFormat - this will allow you to define some output-format for your float-values.

But it is usually a bad idea to store monetary values in binary floatinf-point-types (like float or double) since you will run into rounding-issues as soon as you use values like 0.1 (decimal). Better use somthing like java.math.BigDecimal or (I like that even better) a custom-class for storing fixed-point-values that internally uses an ìnt or a long and a some scale.

Upvotes: 3

Related Questions