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
2 answers

How to display 3 decimal points without round up?

I am making an app which need to display 3 decimal points i achieve this by NumberDecimal but the issue is if 4th digit is >5 then 3rd digit automatically increase. I want to show exact figure for ex : Result : 100.2356 Output …
Mehul Ranpara
  • 4,245
  • 2
  • 26
  • 39
0
votes
1 answer

Convert time to float and viceversa in Java

I need to show some times value on a linear chart and I built a snippet code to convert the values from time to float in Java. My code doesn't works very well because I can't convert from float to time... This is my result: From time to float: 7:43…
user3449772
  • 749
  • 1
  • 14
  • 27
0
votes
2 answers

how to convert big decimal value to decimal in javascript

var zx =1800; I have some value in big decimal value i need to convert it as decimal in javascript. I have tried using zx.doubleValue() method but i m getting error as "Uncaught ReferenceError: Double is not defined" In browser console.
Nandhu
  • 3
  • 2
  • 4
0
votes
1 answer

Java's BigDecimal setScale

Thanks for any advice. Why is this: import java.math.*; public class bdt { public static void main (String [] args) { BigDecimal a = new BigDecimal ("1.0"); BigDecimal b = new BigDecimal ("3.0"); BigDecimal c = new…
failure
  • 215
  • 1
  • 3
  • 12
0
votes
1 answer

How do You Find the Number of Places After the Decimal Point with BigDecimal?

I'm trying to use BigDecimals to calculate something and then round to 5 decimal places if it has more than that. How can I do this? Would scale() work?
0
votes
1 answer

BigDecimal Rounding discrepancy using string and (int, long, double) constructors

What is the difference between using different constructors in bigdecimal when using round off. When running the below code: public class RoundTest { /** * @param args */ public static void main(String[] args) {//2.425 …
Harika Mamidi
  • 452
  • 4
  • 20
0
votes
2 answers

How to get precision of BigDecimal type data in an @Entity class

I have an @Entity class in which there is an instance like this @Column(name="some_column_in_table", precision=3, scale=1) private BigDecimal someColumnInTable; How can I get precision of that instance?
वरुण
  • 1,237
  • 3
  • 18
  • 50
0
votes
3 answers

BigDecimal behavior in Java

public class Test { public static void main(String[] args){ System.out.println(new BigDecimal(58.34)); } } If I run above given program in Java, it is giving me output like: 58.340000000000003410605131648480892181396484375 Why is…
Vishal Zanzrukia
  • 4,902
  • 4
  • 38
  • 82
0
votes
1 answer

BigDecimal attribute changes every page reloading

I was noticed that BigDecimal attribute in my db row changing every page reloading. sum: # ctrl+r sum: # ctrl+r sum: # Is it ok?
anndrew78
  • 196
  • 1
  • 20
0
votes
2 answers

BigDecimal Incorrect Round

I have this result of division: 4893.305785123966785163027491292661448576748 I want to round to 4893.30, but it always returns 4893.31. but when the second decimal will be 6 or more i want to round up. new…
Ignacio
  • 121
  • 3
  • 10
0
votes
1 answer

Ruby on Rails BigDecimal not adding properly

I am trying to make a form, in which a user can input a number (withdraw/deposit) and then the amount will show in a post. But, whatever I tried, the BigDecimals do not add up. class MicropostsController < ApplicationController before_action…
Steve
  • 23
  • 6
0
votes
1 answer

java - compare BigInteger with BigDecimal

I want to compare a BigInteger with a BigDecimal. For example, the integer 10 should be equal to the decimal 10.0. Why does the following return false? I am creating a new decimal from the integer, and then comparing the two…
Jevo Taren
  • 179
  • 8
0
votes
1 answer

BigDecimal is losing precision

I'm using BigDecimal, and it lost precision when it print rate and add the rate. import java.math.MathContext; import java.math.BigDecimal; public class Calc { public static void main( String[] args ) { MathContext mc = new…
noboru
  • 11
  • 1
  • 1
0
votes
1 answer

BigDecimal to Currency with -0.0

I am working on reports for a website and I am currently thinking of what would be the best way to handle BigDecimal -0.0's. The database I'm working with has a lot of them. When these -0.0's are put through number_to_currency(), I get "$-0.00". My…
Isaac
  • 2,246
  • 5
  • 21
  • 34
0
votes
3 answers

How can I fix this method that convert Number in String to show the correct number of decimal digits?

I have the following problem. I am using this method to convert a Number (as a BigDecimal) to a formatted string: /** * @param n il Number da formattare * @param thou_sep separator for hundreds * @param dec_sep separator for decimal digits *…
user4296472