Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:18:42+00:00 2026-05-28T08:18:42+00:00

I have two @Entity s, both with a BigDecimal field as follows: in one

  • 0

I have two @Entitys, both with a BigDecimal field as follows:

in one module:

@Entity
@Table(name = "price_range")
public class PriceRange extends AbstractPersistable<Long> {
    @Column(name = "price", precision = 19, scale = 4)
    private BigDecimal price;

and in another module:

@Entity
@Table(name = "invoice_position")
public class InvoicePosition extends AbstractPersistable<Long> {
    @Column(name = "optimized_cost", precision = 19, scale = 4)
    private BigDecimal optimizedCost;

both create tables in my database with the correct precision and scale values:

Table invoice_position
======================
id,optimized_cost, ...
----------------------
optimized_cost   decimal(19,4)

and

Table price_range
=================
id, price, ...
-----------------
price            decimal(19,4)

A Test Frontend saves the values correctly to the database.

However in a unit test, one of the two returns a value with a rounding error:

0.520000000000000017763568394002504646778106689453125

(debugger says: sacle = 51 and precision = 0)

while the other is working fine:

0.5200

(debugger says: scale = 4, precision = 4)

Both values are retrieved from the database in the same way (with an EntityManager building a CriteriaQuery with a CriteriaBuilder inside a JpaRepository):

List<Invoice> invoices = invoiceProvider.findAll();
List<PriceRange> priceRanges = priceRangeProvider.findAll();

What could be the problem here? Or better: Where could it go wrong, if the Entity has the correct scale and precision and the database as well?

I’m quite at a loss here, where can I look for the error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:18:43+00:00Added an answer on May 28, 2026 at 8:18 am

    Alright, marking this as answered as per comments with the solution being this

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code: @Entity @Table(name=person) @Inheritance(strategy=InheritanceType.JOINED) public class Person { private
A have two entities. For example timing settings and orders. @Entity public class TimingSettings{
Assume that I have two entities as follows: class Blog { public Blog() {
I have two entity classes annotated in the following way @Entity class A {
I have two classes an Arc class and a Line class public class Arc
I have two entity sets with entities of the same name with properties of
Using EF 4.0. I have two entity models, both named CoreEntities, but in different
I have a two entity classes called User and Group, both reserved words that
Say I have an entity as follows: Restaurant Id : int Name : string
I have this simple situation: @Entity public class Customer{ @ManyToMany(fetch=FetchType.EAGER) @Cascade(CascadeType.SAVE_UPDATE) private List<Product> products=new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.