Questions tagged [bigdecimal]

BigDecimal is a numeric object type in Java that represents decimal numbers with arbitrary precision.

Because double and float use a fixed amount of memory (64 and 32 bits respectively), they have limited precision which can lead to rounding errors, and more importantly, they cannot be used to represent all decimal fractions exactly as they use two's complement.

BigDecimal solves these problems by providing arbitrary precision and by using a decimal representation of their values.

The BigDecimal class also provides operations for arithmetic, scale manipulation, rounding, comparison, hashing, and format conversion.

More information can be found in the BigDecimal Javadoc

1677 questions
0
votes
1 answer

How does Grails handles between constraints and messages.properites

In my grails 2.3.11 project, I want to show Please enter a positive numeric value for salaryon my screen if the negative value is inputted. But it displayed Property [salary] with value [-9] is less than minimum value [0] Constraints in my domain…
0
votes
2 answers

Get bigdecimal value with scale

I have a string which has value 7. I need to convert this value in big decimal equivalent 7.000000. I tried BigDecimal(String val) and BigDecimal(BigInteger val, MathContext mc) constructors of BigDecimal but that did not work they all return 7. How…
वरुण
  • 1,237
  • 3
  • 18
  • 50
0
votes
1 answer

Java- Implementation of Bernoulli Numbers in new method

I am having trouble editing an existing implementation of Bernoulli numbers in Java which has the BigRational helper class. The original implementation puts the calculation of the Bernoulli numbers inside the Main method. I made a new class to…
Axion004
  • 943
  • 1
  • 11
  • 37
0
votes
4 answers

Remove leading zeros behind comma in BigDecimal

I have 2 BigDecimals, and I want to remove the same amount leading zeros for both numbers, even those behind the comma. Is there any way of doing that without the expensive toString conversion? Heres some examples of how I want it to look…
Distjubo
  • 959
  • 6
  • 21
0
votes
1 answer

HV000030: No validator could be found for type: java.math.BigDecimal

I have a field: Ordinality DB: ORDINALITY NOT NULL NUMBER(2) @Column(name="ORDINALITY") @NotNull(message="Ordinality is Mandatory") @Size(max=2,message="Ordinality exceeded the limit, Max. 2 numbers are allowed.") private BigDecimal…
Asif Billa
  • 821
  • 2
  • 15
  • 28
0
votes
2 answers

BigDecimal, issue with setScale

I am doing this: (obj.getValue().divide(weight)).setScale(3, RoundingMode.HALF_DOWN) and I am getting this error : java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. Where do I need to put…
user1260928
  • 3,269
  • 9
  • 59
  • 105
0
votes
1 answer

Java + Spring - Put a message on @DecimalMin constraint

Simple enough: How do you put a message on a @DecimalMin constraint? I know you can use message with the @Size constraint, but how would you do it with @DecimalMin? I'm using @DecimalMin on a BigDecimal, as my variable was a decimal and docs said…
Mingle Li
  • 1,322
  • 1
  • 15
  • 39
0
votes
1 answer

sidekiq suddenly stops working

I'm using sidekiq to run background processes in a rails application. It was working fine since yesterday, but now when i try to run it with sidekiq in a command line interface I get WARN: Unresolved specs during Gem::Specification.reset: …
Kasama
  • 83
  • 2
  • 10
0
votes
1 answer

DAO Setter shows NullPointerException error when setting the BigDecimal value - Java Swing

I am getting following error when I set decimal values. Please ignore the naming convention, sorry it is being copied from legacy application. Error Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at…
Shamseer
  • 682
  • 1
  • 11
  • 24
0
votes
2 answers

How to multiply -1 with BigDecimal

In Java, I have a big decimal number , I want to multiply with -1. BigDecimal amount, total; total = amount*-1; If i give like this, it is throwing error upfront. How can I multiply -1 with bigdecimal number.
user3242119
  • 43
  • 2
  • 11
0
votes
1 answer

What postgres data type should I use for sql that returns a big decimal in Rails

I have an app where I'm trying to generate a dollar amount into a new AR record called Metric. I've written the following simple class method to generate a new metric method: def self.last_year m = Metric.new m.name =…
nulltek
  • 3,247
  • 9
  • 44
  • 94
0
votes
1 answer

Loss of accuracy with large values

I am having a problem with large values. Please help me. Scanner scanner=new Scanner(System.in); double rate=1.0000; double value=scanner.nextDouble(); value*=rate; BigDecimal bigDecimal=new…
abdul rahuman
  • 175
  • 1
  • 1
  • 13
0
votes
3 answers

How to do this in Bigdecimal

I'm new to Java. I'm creating small tool and I'm calculating using Bidecimal. I need to do this with bigdecimal. But I don't know how to do it? balance= a%b; Thanks in advance. FxMax
FxMax
  • 472
  • 1
  • 5
  • 9
0
votes
1 answer

How to properly compare database-persisted BigDecimal to another value using ActiveRecord?

The objective is to use ActiveRecord methods like #where and #first_or_create to properly compare a database-persisted BigDecimal value against a Float or String value. create_things migration: t.decimal :position, :precision => 10, :scale =>…
s2t2
  • 2,462
  • 5
  • 37
  • 47
0
votes
2 answers

Correct way to format a notation of a number with decimal scale in Java without dividing

I have done a reading about number conversions in Java because I need to format a number inside my Android application. I'm currently holding a long variable with 4 digits long variable_1 = 2203; And this is what I'm looking to print 220.3 What I…
Machado
  • 14,105
  • 13
  • 56
  • 97