bigdecimal

Scale() of Divide method in BigDecimal

独自空忆成欢 提交于 2019-12-05 06:25:49
new BigDecimal("37146555.53880000").divide(new BigDecimal("1000000")).scale() This returns 10 . But according to the API, the divide method: Returns a BigDecimal whose value is (this / divisor), and whose preferred scale is (this.scale() - divisor.scale()); So in this case, 37146555.53880000's scale is 8 , and 1000000 's scale is 0 . So the result should have a scale of 8 , not 10 . What am I missing here? Thanks Andrei Fierbinteanu The actual result is 37.1465555388 whose scale must be 10 for it to be exact. What the JavaDoc says is that the preferred scale is the difference meaning that if

花了几个小时总结了一些容易出错的 Java 知识点!

自闭症网瘾萝莉.ら 提交于 2019-12-05 06:09:42
摘自: https://www.cnblogs.com/javaguide/p/11891447.html 花了几个小时总结了一些容易出错的 Java 知识点! 本文已经收录自 JavaGuide (61k+Star!【Java学习+面试指南】 一份涵盖大部分Java程序员所需要掌握的核心知识。欢迎 Star!欢迎骚扰!) 原文地址:https://javaguide.cn/2019/08/20/java/java%E5%9F%BA%E7%A1%80/Java%E7%96%91%E9%9A%BE%E7%82%B9/ 1. 基础 1.1. 正确使用 equals 方法 Object的equals方法容易抛空指针异常,应使用常量或确定有值的对象来调用 equals。 举个例子: // 不能使用一个值为null的引用类型变量来调用非静态方法,否则会抛出异常 String str = null; if (str.equals("SnailClimb")) { ... } else { .. } 运行上面的程序会抛出空指针异常,但是我们把第二行的条件判断语句改为下面这样的话,就不会抛出空指针异常,else 语句块得到执行。: "SnailClimb".equals(str);// false 不过更推荐使用 java.util.Objects#equals (JDK7 引入的工具类)。

SpringDataSolr入门

只谈情不闲聊 提交于 2019-12-05 05:05:44
Spring Data Solr 入门 2.1 Spring Data Solr 简介 虽然支持任何编程语言的能力具有很大的市场价值,你可能感兴趣的问题是:我如何 将 Solr 的应用集成到 Spring 中 ? 可以, Spring Data Solr 就是为了方便 Solr 的开发所研制的一个框架,其底层是对 SolrJ (官方 API )的封装。 2.2 Spring Data Solr 入门小 Demo 2.2.1 搭建工程 (1) 创建 maven 工程, pom.xml 中引入依赖 < dependencies > <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data- solr </artifactId> <version> 1.5.5 .RELEASE</version> </dependency> < dependency > < groupId > org.springframework </ groupId > < artifactId > spring-test </ artifactId > < version > 4.2.4.RELEASE </ version > </ dependency > < dependency > < groupId

Spring Data Solr入门小Demo

喜欢而已 提交于 2019-12-05 05:04:59
package com.offcn.pojo; import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; import org.apache.solr.client.solrj.beans.Field; public class TbItem implements Serializable{ @Field private Long id; @Field("item_title") private String title; private String sellPoint; @Field("item_price") private BigDecimal price; private Integer stockCount; private Integer num; private String barcode; @Field("item_image") private String image; private Long categoryid; private String status; private Date createTime; private Date updateTime; private String itemSn; private BigDecimal

spring data solr入门

江枫思渺然 提交于 2019-12-05 05:01:52
1.Spring Data Solr 入门 1.1 Spring Data Solr 简介 虽然支持任何编程语言的能力具有很大的市场价值,你可能感兴趣的问题是:我如何 将Solr 的应用集成到 Spring 中 ? 可以, Spring Data Solr 就是为了方便 Solr 的开发所研制的一个框架,其底层是对 SolrJ (官方 API )的封装。 1.2 Spring Data Solr 入门小 Demo 1.2.1 搭建工程 (1) 创建 maven 工程, pom.xml 中引入依赖 <dependencies> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-solr</artifactId> <version>1.5.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.2.4.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId

hibernate returning BigDecimal datatype instead of long

*爱你&永不变心* 提交于 2019-12-05 04:44:28
The hibernate named query returns a BigDecimal for a column that has datatype NUMBER. select col1 as "col1" from table1 union select col2 as "col1" from table2 On client side, I expect the datatype of col1 to be long (primitive) I do this: <return-scalar column="col1" type="java.lang.Long" /> or <return-scalar column="col1" type="long" /> In both cases, I get : java.lang.ClassCastException: java.math.BigDecimal incompatible with java.lang.Long How can I fix this? My suspiscion, something wrong with the aliasing? Oracle NUMBER maps to BigDecimal in Hibernate by default. Try setting the type to

Is there any IEEE 754 standard implementations for Java floating point primitives?

左心房为你撑大大i 提交于 2019-12-04 18:33:51
问题 I'm interested if Java is using IEEE 754 standard for implementing its floating point arithmetic. Here I saw this kind of thing in documentation: operation defined in IEEE 754-2008 As I understand positive side of IEEE 754 is to increase precision of floating point arithmetics so if I'll use double or float in Java would presision of computations be same as in BigDecimal ? And if not than what's the point of using IEEE 754 standard in Math class? 回答1: I'm interested if Java is using IEEE 754

toPlainString() 和 toString()(转载)

旧城冷巷雨未停 提交于 2019-12-04 16:27:32
函数 toPlainString() 和 toString() 对于 BigDecimal b ; (b=(0.4321)^ 20) String s = b.toPlainString() ; System.out.println(s) ; 输出为: 0.00000005148554641076956121994511276767154838481760200726351203835429763013462401 若String s = b.toString() ; 输出为: 5.148554641076956121994511276767154838481760200726351203835429763013462401E-8 在得到的小数,要对其小数点后面的零进行处理,用到:BigDecimal stripTrailingZeros() 返回数值上等于此小数,但从该表示形式移除所有尾部零的 BigDecimal。 对得到的数据用科学计数法就用:String toPlainString() 返回不带指数字段的此 BigDecimal 的字符串表示形式。 通俗来讲就是直接显示,不用科学计数法表示。 import java.math.BigDecimal;public class BigDecimalDemo { public static void main(String[]

BigDecimal Underflow

拟墨画扇 提交于 2019-12-04 14:59:33
I am trying to render a fractal called the "Lorenz Attractor" with Java. Because double does not work (values out of range), I decided to choose BigDecimals. After 38 iterations my code crashes, it gets me an ArithmeticException (Underflow). Heres some of the code: BigDecimal xnew = this.x.add(this.hBig.multiply(BigDecimal.TEN).multiply(this.x.add(this.y.negate()))); //This is the line that crashes BigDecimal ynew = this.y.add(this.hBig.multiply(this.x.negate().multiply(this.z)).add(ZWENTYEIGHT.multiply(this.x.add(this.y.negate())))); BigDecimal znew = this.z.add(this.hBig.multiply(this.x

本金利息自动计算问题

纵然是瞬间 提交于 2019-12-04 13:26:38
小明月薪10000元,每月最后一天发放工资,领到工资后立即存入某宝,某宝10000元利息为每月30元(月底结算),年终奖为50000(12月发)。请问,N个月以后,小明获得的利息是多少,总存款是多少? 第1个月:(0/10000)*30+10000=10030 第2个月:10030+(10030/10000)*30+10000=20030.09 第3个月:20030.09+(20030.09/10000)*30+10000=30090.18 设第N个月的总存款为K,则第N+1个月的总存款 J = K+K/10000*30+10000 以上的公式为普通月份的存款计算,不包含年终奖。设开始存款的月份为M,则第N个月的逻辑分解如下: 如果(M+N-1)%12 == 0,则当月年终奖为50000 如果(M+N-1)%12 != 0,则当月年终奖为0 程序如下: import java.math.BigDecimal; /* * @author szh * @date 2019年11月15日 下午3:34:50 * @version 1.0 */ public class Test { // 月薪 private static final BigDecimal SALARY = new BigDecimal("10000"); // 年终奖 private static final