bigdecimal

Regarding BigDecimal

I have a csv file where amount and quantity fields are present in each detail record except header and trailer record. Trailer record has a total charge values which is the total sum of quantity multiplied by amount field in detail records . I need to check whether the trailer total charge value is equal to my calculated value of amoun...

Override BigDecimal to_s default in Ruby

As I retrieve data from a database table an array is populated. Some of the fields are defined as decimal & money fields and within the array they are represented as BigDecimal. I use these array values to populate a CSV file, but the problem is that all BigDecimal values are by default represented in Scientific format (which is the de...

Regarding Big Decimal

I have a csv file where amount and quantity fields are present in each detail record except header and trailer record. Trailer record has a total charge values which is the total sum of quantity multiplied by amount field in detail records . I need to check whether the trailer total charge value is equal to my calculated value of amount ...

Regarding BigDecimal

i do the below java print command for this double variable double test=58.15; When i do a System.out.println(test); and System.out.println(new Double(test).toString()); It prints as 58.15. When i do a System.out.println(new BigDecimal(test)) I get the below value 58.14999999999999857891452847979962825775146484375 I am able to unders...

How to use BigDecimal in swing GUIs?

I'm using BigDecimal to represent product prices in a Java SE application. What swing component(s) should I use in order to allow the user to input numbers with only two decimal places and bound it to a BigDecimal variable/Object's property. (Checking that as the user types)? I've been playing with JTextField, JFormattedTextField, Numb...

Java BigDecimal memory usage?

Is there a guideline for estimating the amount of memory consumed by a BigDecimal? Looking for something similar to these guidelines for estimating String memory usage. ...

Advice welcomed on creating my own Swing component

Recently I asked which was the best Swing component to bind to a BigDecimal variable (with some particular editing properties). It turns out that none of the standard Swing components suit me completely, nor did the third-party Swing component libraries I've found out there. So I’ve decided to create my own Swing component. Component de...

BigDecimal, division & MathContext - very strange behaviour

CentOs 5.4, OpenJDK Runtime Environment (build 1.6.0-b09) MathContext context = new MathContext(2, RoundingMode.FLOOR); BigDecimal total = new BigDecimal("200.0", context); BigDecimal goodPrice = total.divide(BigDecimal.valueOf(3), 2, RoundingMode.FLOOR); System.out.println("divided price=" + goodPrice.toPlainString()); // prints 6...

BigDecimal to_s does not match to_f

Is the BigDecimal class broken? It seems like the following should never, ever occur: Note that a.to_f != a.to_s.to_f a.class => BigDecimal a.to_f => 18658.1072928 a.to_s => "10865.81072928" b.class => BigDecimal b.to_f => 10000.0 b.to_s => "10000.0" (...

The best cross platform (portable) arbitrary precision math library

Dear ninjas / hackers / wizards, keywords: bignum, bigint, GMP, MPFR, decNumber, BigInteger, BigDecimal, java.math.BigInteger, java.math.BigDecimal, System.Numerics.BigInteger I'm looking for a good arbitrary precision math library in C or C++. Could you please give me some advices / suggestions? The primary requirements: It MUST ha...

Java: What is the right way to convert String into a valid amount of money(BigDecimal)

Hi, I have to convert an incoming String field into a BigDecimal field that would represent a valid amount of money, for example: String amount = "1000"; BigDecimal valid_amount = convert(amount); print(valid_amount.toString())//1000.00 What is the right API to use convert a String into a valid amount of money in Java (eg: apache co...

Is there a decimal math library for JavaScript?

Is there a mature library for doing decimal-based math, possibly arbitrary-precision, in JavaScript? Edit: I want this information for a reference page on floating-point-related problems and alternatives to use when binary floating-point is inappropriate: http://floating-point-gui.de/ ...

Avoid the problem with BigDecimal when migrating to Java 1.4 to Java 1.5+

Hello, I've recently migrated a Java 1.4 application to a Java 6 environment. Unfortunately, I encountered a problem with the BigDecimal storage in a Oracle database. To summarize, when I try to store a "7.65E+7" BigDecimal value (76,500,000.00) in the database, Oracle stores in reality the value of 7,650,000.00. This defect is due to t...

Groovy as a substitute for Java when using BigDecimal?

I have just completed an evaluation of Java, Groovy and Scala. The factors I considered were: readability, precision The factors I would like to know: performance, ease of integration I needed a BigDecimal level of precision. Here are my results: Java void someOp() { BigDecimal del_theta_1 = toDec(6); BigDecimal del_theta_2...

How to index BigDecimal values in Lucene 3.0.1

I have some BigDecimal values which should be indexed for searching. Lucene has NumericField but it has setters only for long, double, float and int. I could store it as a String but then I would not benefit from NumericRangeQuery. How you have stored your BigDecimals? Any best practices to share? ...

ArithmeticException thrown during BigDecimal.divide

I thought java.math.BigDecimal is supposed to be The Answer to the need of performing infinite precision arithmetic with decimal numbers. Consider the following snippet: import java.math.BigDecimal; //... final BigDecimal one = BigDecimal.ONE; final BigDecimal three = BigDecimal.valueOf(3); final BigDecimal third = one.divide(three); ...

java.bigDecimal divide in ruby environment

I right script in Ruby that include java classes require 'java' include_class 'java.math.BigDecimal' include_class 'java.math.RoundingMode' during the script I need to divide 2 java.bigDecimal one = BigDecimal.new("1") number1 = BigDecimal.new("3") number1 = one.divide(number1,RoundingMode.new(HALF_EVEN)) since I don't have inte...

How do I know if a BigDecimal failed to parse?

Hi guys, I'm importing data from a csv, I need to cast some values to BigDecimal, and raise an error if they can't be parsed.. From testing, BigDecimal("invalid number") returns a BigDecimal of 0. This would be ok, but kind of messy, except a valid value is 0... Float("invalid number") acts differently and throws an exception... My ...

JAXB, BigDecimal or double?

I working on different web-services, and I always use WSDL First. JAXB generates for a Type like: <xsd:simpleType name="CurrencyFormatTyp"> <xsd:restriction base="xsd:decimal"> <xsd:totalDigits value="13"/> <xsd:fractionDigits value="2"/> <xsd:minInclusive value="0.01"/> </xsd:restriction> </xsd:simpleTy...

what is the equivalent for java class : BigDecimal in c#

hi all , BigDecimal is a class in java.math package it has a lot of benefits for handling big numbers with certain scale . is there an equivalent class or data type in c# with this features ...