This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

BigDecimal 0  RSS feed

X Luo
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have exprienced something interesting with BigDecimal.

I have a big decimal

// first declare x
BigDecimal x = new BigDecimal (0.00000);
//new re-assign the value
x = new BigDecimal (0.0000000000);
System.out.println(x); //it prints out x = 0E-10

//I then use this x value to update a field in Oracle db table;
//sql is like this:

UPDATE table1
SET field1 = ?
WHERE ..... ;

// the datatype field1 in oracle db is set as number(17,5);

// then use PreparedStatement to set the value for field1:
ps.setBigDecimal(1, x);

//the field1 value gets updated, but not as 0. It has been updated as 10

Can anybody please explain why it works that way? Is it a java problem or oracle problem? And what's the best way to avoid such issue, it only seems to happen to BigDecimal value is 0.

Many thanks,

X Luo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!