由买买提看人间百态

topics

全部话题 - 话题: bigdecimal
1 (共1页)
M*****r
发帖数: 1536
1
来自主题: Java版 - help: Double or BigDecimal
What JDK version r u using?
Also, there are some error/typo in the code you posted.
This works for me in JDK 1.5.0_07.
public class numbertest
{
public static void main(String[] args){
Double a = 0.0017006802721088435;
Double b = 0.0;
Double c = 0.55;
Double d = 0.0;
Double resultInDouble = 1/2*(a-b)*(c+d);
BigDecimal aa = new BigDecimal("0.0017006802721088435");
BigDecimal bb = new BigDecimal("0.0");
BigDecimal cc = new BigDecimal("0.55");
BigDecimal dd = new BigDecimal("0.0");
BigDecimal resul
G*********a
发帖数: 1080
2
来自主题: Java版 - help: Double or BigDecimal
I met a problem of losing precision and please help! I am calculating an
accumulative value shich is quite small, it's the multiplication result of
some numbers look like these:
0.6333333333333334 0.002551020408163265 0.35 0.004251700680272109
0.1496794871794872 0.04421768707482993
0.34761904761904766 0.005952380952380952 0.31 0.008503401360544218
0.17910052910052912 0.05357142857142857
I tried to set the result value as either a Double or a BigDecimal, but
P**M
发帖数: 242
3
来自主题: Java版 - Test your PC speed
Using:
time java Pi xxx (the number of digits your want)
//////////////////////////////////////////////////
import java.math.*;
public class Pi{
private static final BigDecimal ZERO =
BigDecimal.valueOf(0);
private static final BigDecimal ONE =
BigDecimal.valueOf(1);
private static final BigDecimal FOUR =
BigDecimal.valueOf(4);
private static final int roundingMode =
BigDecimal.ROUND_HALF_EVEN;
public Pi() {
}
public static void main(String args[]){
int digits=100;
i
o****i
发帖数: 1706
4
两道作业..我觉得我的答案不好啊..第二道题,现在只学了short,int,float和double.
.所以我想不明白,因为查了JAVA的资料,This data type should never be used for
precise values, such as currency. For that, you will need to use the java.
math.BigDecimal class instead. Numbers and Strings covers BigDecimal and
other useful classes provided by the Java platform. 可是BigDecimal我还没学啊
..迷糊了..期待牛人能帮我下啊..小弟初学啊..谢谢啦..
1.If we were dealing only with integer values, would we be able to discern
immediately if the answer made mathematical sense? Why or why n
c****o
发帖数: 515
5
If the operations you plan to do with the p-values involve only
multiplication, division and exponentiation, take their logs and do
operations on the log-p values. Otherwise, you can use MATLAB's Java
interface to call java.math.BigDecimal
http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecim
e****e
发帖数: 418
6
来自主题: JobHunting版 - A电面
Just my 2 cents.
public class Cloth {
int size;
int quantity;
String brand;
String name;
BigDecimal price;
}
public class ClothService {

// lookup cloth table in database to see if quality is 0;
public boolean query(Cloth c) {
//...
}

public void addCloth(Cloth c) {
//...
}

public void soldCloth(Cloth c) {
//...
}
}
public class Client {
public static void main(String[] args) {
Cloth c = new Cloth();
... 阅读全帖
l*n
发帖数: 529
7
来自主题: JobHunting版 - java做题时如何处理overflow
有可能overflow的话,就在最开始进行一些限制吧,或者换long。再不行就上
BigDecimal。
Q****a
发帖数: 296
8
来自主题: JobHunting版 - java Math.sqrt 的精度是?
我搜了一下源码,没找到具体的implementation,大牛能大概说说(或者给个link)正
确的算法么? 难道是用BigDecimal算出来,再convert 到double? 还是用改良版的牛
顿迭代?万谢 ~~
n*******s
发帖数: 17267
9
BigDecimal, 金融肿么可能不需要?
z*******o
发帖数: 4773
10
Use BigDecimal and thank me later.
L*******t
发帖数: 782
11
来自主题: JobHunting版 - Airbnb面经
和钱有关的都要用BigDecimal嘛。

刀?
e*******s
发帖数: 1927
12
来自主题: JobHunting版 - Max points on a line
Max points on a line这道题,用算斜率的办法,把slope和在这个线上的点的数目放
到hashmap里。
但是leetcode上似乎有人加了一个test case,三个点
[0,0], [94911151, 94911150], [94911152, 94911151]
这样的话算出来的斜率用double是一样的,实际上这三个点不在一条线上所以出错了
用的是java,试了BigDecimal好像还是不行,这种情况怎么处理呀?大家指点一下。
原题如下:
Given n points on a 2D plane, find the maximum number of points that lie on
the same straight line.
/**
* Definition for a point.
* class Point {
* int x;
* int y;
* Point() { x = 0; y = 0; }
* Point(int a, int b) { x = a; y = b; }
* }
*/
public c... 阅读全帖
z****e
发帖数: 54598
13
来自主题: PhotoGear版 - 说道C语言
这个问题很好解决
BigDecimal类搞定
r***l
发帖数: 67
14
that's the correct answerm not very convenient to use though.
also, take a look at BigDecimal. If you are doing double/float calculation, it
may help you.
V***l
发帖数: 2108
15
来自主题: Java版 - 海量级数据的算法问题
用java.math.BigDecimal ?
G*********a
发帖数: 1080
16
来自主题: Java版 - help: Double or BigDecimal
1.5. sorry, i did type something wrong above.
thank u very much for ur testing, i also found the problem of my previous
code was mainly due to 1/2 in java in an interger type 0, i should have used
0.5 instead.
r**d
发帖数: 316
17
use BigDecimal class
z*******3
发帖数: 13709
18
Number的声明,说是用interface标记才是正统蠢材
估计没写过代码,因为小本都知道
Integer.parse("123");
interface能调用方法么?废材,说一个例子就错一个例子
尼玛,这个蠢货怎么就这么爱现呢?给他台阶下还不懂得下
public abstract class Number
extends Object
implements Serializable
The abstract class Number is the superclass of classes BigDecimal,
BigInteger, Byte, Double, Float, Integer, Long, and Short.
Subclasses of Number must provide methods to convert the represented numeric
value to byte, double, float, int, long, and short.
Since:
JDK1.0
z*******3
发帖数: 13709
19
Number的声明,说是用interface标记才是正统蠢材
估计没写过代码,因为小本都知道
Integer.parse("123");
interface能调用方法么?废材,说一个例子就错一个例子
尼玛,这个蠢货怎么就这么爱现呢?给他台阶下还不懂得下
public abstract class Number
extends Object
implements Serializable
The abstract class Number is the superclass of classes BigDecimal,
BigInteger, Byte, Double, Float, Integer, Long, and Short.
Subclasses of Number must provide methods to convert the represented numeric
value to byte, double, float, int, long, and short.
Since:
JDK1.0
n*w
发帖数: 3393
20
来自主题: Programming版 - C# is light-years ahead of Java now
我倒不认为这些features是 trivial的。
From embracing dynamic programming, bring asynchronicity into
the language, introduce iterators, functional programming constructs,
embrace parallelism and got a great implementation of generics.
觉得java拿了c++一大块的最重要原因(之一)是type safe。
下面这个别人总结的java和c#的不同点包括了一些trivial或不trivial的东西。
Generics are completely different between the two; Java generics are just
a compile-time "trick" (but a useful one at that). In C# and .NET
generics are maintained at execution time too, and work... 阅读全帖
z****e
发帖数: 54598
21
来自主题: Programming版 - node不负众望,完胜Java
都有啊,游戏不就是最复杂的应用?
游戏才能给用户最好的体验,所以问题集中在游戏上
javafx目前还不错,android也还好,就剩下ios了
想想以后是不是跟置顶那个zlike合作,他做ios做得蛮好
dsl我自己定义的呀,在想将来要不要开源
不过主要是做大数据的处理,主要思想就是用string实现+-*/^的操作
这样就不怕int或者long的限制了,对于nosql的hbase里面一些number的操作
就不怕了,尤其是当一些number特别大,一加就会溢出
如果用bigdecimal的话,^很不方便,不能开方
当然trade off是比较慢,然后自己定义了一些语法
比如不用写main,转译后可以自己生成public static void main(String args[])
以及一个private void main,然后再调用酱紫
其实也没啥东西,技术上不是主要问题,关键是美工之类的
很难找,基本上都找不到,我试过n个,累了,还是先用免费的素材
搞好了之后再找美工一个一个试

C
K*********n
发帖数: 2852
22
Scala纯新手,写了点测试代码:
###### build.sbt #########
name := "Train NB"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-core" % "1.2.0",
"commons-io" % "commons-io" % "2.4",
"com.google.code.gson" % "gson" % "2.2.4",
"org.la4j" % "la4j" % "0.4.9"
)
javacOptions ++= Seq("-source", "1.7", "-target", "1.7")
####### scala code ##########
package app.mycompany
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apa... 阅读全帖
z*******n
发帖数: 1034
23
来自主题: MobileDevelopment版 - [教程]Android开发教程 [0] 编程语言
盖茨和艾伦早年编程实现fixed point 运算(类似java的java.math.BigDecimal)功能
的时候,
不知道不会还是忙就找别人做的,后来Intel就找到William Kahan,一个加拿大籍的数
学家,
实现了浮点运算,William Kahan是IEEE754标准的主要推动者,后来就中了图灵奖,再
后来他就写了篇文章批评一个语言,这个语言就是Android平台大部分场景适用的开发
语言,叫做java.
加拿籍的计算机科学家James Gosling一般被认为是java语言之父,可是他太无趣了没什
么好说的,我们看看在他之前做了重要工作的个人叫做Patrick Naughton,这里有个访
谈连接http://www.forbes.com/asap/1997/1201/144.html,他呢,认识教主,本来就是要离开Sun公司去教主那里上班了,后来Sun就开始这个Java项目了就没去,再后来,他在网上约未成年女孩,被FBI钓鱼执法,他就找了个律师,律师很可以,创造了Fantasy Defense,这了有个连接http://www.cbsnews.com/news... 阅读全帖
q*c
发帖数: 9453
24
来自主题: _PathToTruth版 - Re: 龙年愿望
结果用来到处看流星雨了...
而且据说是排队了很多大劫, 那不知道是多少年。
waichi 说计算机表示不了那么大的数, 哈哈,
其实他不知道计算机是可以表示那么大的数的, 用 BigDecimal... :)
1 (共1页)