bigdecimal

Using Struts2 Tags to Formatting Numbers

僤鯓⒐⒋嵵緔 提交于 2020-01-09 05:25:09
问题 I want to format some numbers in our jsp pages. first i define some resources in my porperties format.number.with2Decimal={0,number,#0.00} ...... Question1: i want to know what is the ‘#’ and '0' means? 0.00,#0.00,##.00,###0.00 who can tell me the differences between them? thanks! Question2: if i define a BigDecimal type in my action BigDecimal number1; Then my page should using a format to show this value, 1.if number1=null then show -NIL- 2.if number1=0 then show -NIL- 3.if number1>0 then

conversion BigDecimal Java to c#-like Decimal

北战南征 提交于 2020-01-05 09:14:07
问题 In Java BigDecimal class contains values as A*pow(10,B) where A is 2's complement which non-fix bit length and B is 32bit integer. In C# Decimal contains values as pow (–1,s) × c × pow(10,-e) where the sign s is 0 or 1, the coefficient c is given by 0 ≤ c < pow(2,96) , and the scale e is such that 0 ≤ e ≤ 28 . And i want to convert Java BigDecimal to Something like c# Decimal in JAVA. Can you help me . I have some thing like this class CS_likeDecimal { private int hi;// for 32bit most

conversion BigDecimal Java to c#-like Decimal

给你一囗甜甜゛ 提交于 2020-01-05 09:13:15
问题 In Java BigDecimal class contains values as A*pow(10,B) where A is 2's complement which non-fix bit length and B is 32bit integer. In C# Decimal contains values as pow (–1,s) × c × pow(10,-e) where the sign s is 0 or 1, the coefficient c is given by 0 ≤ c < pow(2,96) , and the scale e is such that 0 ≤ e ≤ 28 . And i want to convert Java BigDecimal to Something like c# Decimal in JAVA. Can you help me . I have some thing like this class CS_likeDecimal { private int hi;// for 32bit most

Requiring Active_record 4.1.8 gives warnings

别来无恙 提交于 2020-01-04 16:58:04
问题 I upgraded to 4.1.8 and now when I open a console session and do require "active_record" I get the following output: [1] pry(main)> require 'active_record' /Users/fzondlo/.rvm/gems/ruby-2.0.0-p195/gems/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::BASE /Users/fzondlo/.rvm/gems/ruby-2.0.0-p195/gems/bigdecimal-1.2.5/bigdecimal.bundle: warning: already initialized constant BigDecimal::EXCEPTION_ALL /Users/fzondlo/.rvm/gems/ruby-2.0.0-p195/gems/bigdecimal-1

Bug in Number or BigInteger and BigDecimal (or alternatively in the API documentation of those)?

旧街凉风 提交于 2020-01-04 05:42:12
问题 According to the specification of Number.longValue() the method should... Returns the value of the specified number as a long. This may involve rounding or truncation. However, the BigInteger (and BigDecimal ) overrides this method and returns the 64 low bits of the integer part of the number it represents. From the docs of BigInteger for example: [...]if this BigInteger is too big to fit in a long, only the low-order 64 bits are returned.[...] I claim that either " This may involve rounding

Incorrect division results

泄露秘密 提交于 2020-01-04 02:44:26
问题 I've got a time calculator that has worked reasonably well for a number of years. One thing that always bothered me, though, was that if one used fractional seconds, the results would fall victim to floating-point "errors". So, I recently switched to using this BigDecimal library. Now, I'm getting math errors. Here's a simplified test case from a bug report I received today: 27436 / 30418 is returning 1 instead of the expected 0.9019659412190151 . To illustrate my problem, here's a Javascript

从java8 说起函数式编程

笑着哭i 提交于 2020-01-03 17:19:38
写在前面 为什么要用函数式编程。看例子: final List<BigDecimal> prices = Arrays.asList( new BigDecimal("10"), new BigDecimal("30"), new BigDecimal("17"), new BigDecimal("20"), new BigDecimal("15"), new BigDecimal("18"), new BigDecimal("45"), new BigDecimal("12")); BigDecimal totalOfDiscountedPrices = BigDecimal.ZERO; for(BigDecimal price : prices) { if(price.compareTo(BigDecimal.valueOf(20)) > 0) totalOfDiscountedPrices = totalOfDiscountedPrices.add(price.multiply(BigDecimal.valueOf(0.9))); } System.out.println("Total of discounted prices: " + totalOfDiscountedPrices); 更优雅的方式,是使用声明式的代码: final BigDecimal

Neat way to find the number of significant digits in a BigDecimal?

寵の児 提交于 2020-01-03 17:18:48
问题 I do not want to limit the number of significant digits in a BigDecimal. I only want to find the number of significant digits that number has. Is there a way to do this without converting the number to string and count the number characters? 回答1: I believe you want a combination of stripTrailingZeros, precision and scale, as demonstrated here: import java.math.*; public class Test { public static void main(String[] args) { test("5000"); // 4 test("5000.00"); // 4 test("5000.12"); // 6 test(

JTextField Specific format checking

风流意气都作罢 提交于 2020-01-03 05:56:08
问题 I want to check if the input entered to my JTextField1 equal to shown sample picture below, how to do that? I can only check if numbers entered by putting below code in to try block and catch NumberFormatException try { taxratio = new BigDecimal(jTextField1.getText()); } } catch (NumberFormatException nfe) { System.out.println("Error" + nfe.getMessage()); } 回答1: Here are two options: A JTextField with an InputVerifier . The text field will not yield focus unless its contents are of the form

Override BigDecimal to_s default in Ruby

谁说胖子不能爱 提交于 2020-01-02 09:43:54
问题 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 default behaviour of the BigDecimal to_s method). I can show the values by using to_s('F'), but how can I override the default? 回答1: This is built on @Farrel's