bigdecimal

Convert seconds value to hours minutes seconds?

筅森魡賤 提交于 2019-11-26 21:38:18
I've been trying to convert a value of seconds (in a BigDecimal variable) to a string in an editText like "1 hour 22 minutes 33 seconds" or something of the kind. I've tried this: String sequenceCaptureTime = ""; BigDecimal roundThreeCalc = new BigDecimal("0"); BigDecimal hours = new BigDecimal("0"); BigDecimal myremainder = new BigDecimal("0"); BigDecimal minutes = new BigDecimal("0"); BigDecimal seconds = new BigDecimal("0"); BigDecimal var3600 = new BigDecimal("3600"); BigDecimal var60 = new BigDecimal("60"); (I have a roundThreeCalc which is the value in seconds so I try to convert it here

【Java】 float保留两位小数

三世轮回 提交于 2019-11-26 21:04:39
前言: float是浮点数,有时需要做精确的位数处理 正文: 方法1 float f = (float) 34.232323; BigDecimal b = new BigDecimal(f); float f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); //ROUND_HALF_UP表明四舍五入,ROUND_HALF_DOWN表明五舍六入,2:保留两位小数 方法2 float f = 34.232323; DecimalFormat fmt = new DecimalFormat("##0.00"); String s = fmt.format(f); float f1 = Float.parseFloat(s); 参考博客: Java float保留两位小数_ufeng_新浪博客 http://blog.sina.com.cn/s/blog_77a45ee10101qbuy.html 来源: https://www.cnblogs.com/huashengweilong/p/11332206.html

BigDecimal, precision and scale

情到浓时终转凉″ 提交于 2019-11-26 19:31:32
问题 I'm using BigDecimal for my numbers in my application, for example, with JPA. I did a bit of researching about the terms 'precision' and 'scale' but I don't understand what are they exactly. Can anyone explain me the meaning of 'precision' and 'scale' for a BigDecimal value? @Column(precision = 11, scale = 2) Thanks! 回答1: A BigDecimal is defined by two values: an arbitrary precision integer and a 32-bit integer scale . The value of the BigDecimal is defined to be . Precision: The precision is

Is there a C++ equivalent to Java's BigDecimal?

丶灬走出姿态 提交于 2019-11-26 19:01:30
I'm looking for a C++ class that can do decimal floating point arithmetic. Looking through http://speleotrove.com/decimal/ there are links to all sorts of classes that people have written and not maintained. Digging through the decNumber++ stuff led me to some emails showing that GCC will eventually support this functionality. (Formally known as ISO/IEC TR 24733) I'm looking for something I can use as a drop-in replacement for float or double, something that other people are using in their own projects. Hopefully open source. Thanks! EDIT: I should point out that I'm trying to use this to

Is there a decimal math library for JavaScript?

你离开我真会死。 提交于 2019-11-26 19:00:55
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/ Pointy There's been a "port" of the Java BigDecimal class (I think it's here: http://freshmeat.net/projects/js_bigdecimal/ ) for a long time. I looked at it a long time ago and it seemed kind-of cumbersome and huge, but (if that's the one I'm thinking of) it's been used as part of some cryptography tools so there

Java BigDecimal bugs with String constructor to rounding with ROUND_HALF_UP

谁说胖子不能爱 提交于 2019-11-26 18:37:17
问题 I'm trying to implement a new grade rounding to BigDecimal class, and I'm getting a possible bug, must probably I doing something wrong. The code below exposes my problem: public static void main(String[] args) throws IOException { BigDecimal valDouble = new BigDecimal(0.35); valDouble = valDouble.setScale(1, BigDecimal.ROUND_HALF_UP); System.out.println(valDouble.doubleValue()); // prints 0.3 BigDecimal valString = new BigDecimal(new String("0.35")); valString = valString.setScale(1,

Adding up BigDecimals using Streams

怎甘沉沦 提交于 2019-11-26 18:24:12
I have a collection of BigDecimals (in this example, a LinkedList ) that I would like to add together. Is it possible to use streams for this? I noticed the Stream class has several methods Stream::mapToInt Stream::mapToDouble Stream::mapToLong Each of which has a convenient sum() method. But, as we know, float and double arithmetic is almost always a bad idea. So, is there a convenient way to sum up BigDecimals? This is the code I have so far. public static void main(String[] args) { LinkedList<BigDecimal> values = new LinkedList<>(); values.add(BigDecimal.valueOf(.1)); values.add(BigDecimal

金额的计算BigDecimal类

空扰寡人 提交于 2019-11-26 18:06:07
金额的计算BigDecimal类 double d = 9.84; double d2 = 1.22; //注意需要使用BigDecimal(String val)构造方法 BigDecimal bigDecimal = new BigDecimal(Double.toString(d)); BigDecimal bigDecimal2 = new BigDecimal(Double.toString(d2)); //加法 BigDecimal bigDecimalAdd = bigDecimal.add(bigDecimal2); double add = bigDecimalAdd.doubleValue(); //减法 BigDecimal bigDecimalSubtract = bigDecimal.subtract(bigDecimal2); double subtract = bigDecimalSubtract.doubleValue(); //乘法 BigDecimal bigDecimalMultiply = bigDecimal.multiply(bigDecimal2); double multiply = bigDecimalMultiply.doubleValue(); //除法 int scale = 2;//保留2位小数 BigDecimal

java代码实现liunx服务器(cpu、mem(内存)、jvm、堆/非堆、磁盘、服务器、java虚拟机)监控

五迷三道 提交于 2019-11-26 17:53:13
废话不多说 直接贴代码。。。 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.MemoryUsage; import java.lang.management.OperatingSystemMXBean; import java.lang.management.RuntimeMXBean; import java.math.BigDecimal; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Date; import java.util

BigDecimal summary statistics

試著忘記壹切 提交于 2019-11-26 17:25:56
问题 I have a list of BigDecimals. List<BigDecimal> amounts = new ArrayList<>() How do i get the summary statistics of the above list using Java 8 streams without losing precision of upto 3-4 decimal places of the BigDecimal? 回答1: I created a BigDecimal specialization of the generic summary statistics collector of this answer, which allowed extending it to also support summing, hence also calculating an average: /** * Like {@code DoubleSummaryStatistics}, {@code IntSummaryStatistics}, and * {@code