1

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?

newbie
  • 1,884
  • 7
  • 34
  • 55
  • you are doing nothing wrong. try using NumberFormat http://docs.oracle.com/javase/7/docs/api/java/text/NumberFormat.html – Scary Wombat Jun 18 '14 at 07:26
  • 2
    You should use `BigDecimal` here and for any currency values. http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency – pingw33n Jun 18 '14 at 07:30

1 Answers1

3

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.

piet.t
  • 11,718
  • 21
  • 43
  • 52