双精度乘以精度和逗号 [英] Double number's multiplication with out precision and commas

查看:133
本文介绍了双精度乘以精度和逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组,一个双数组,如...

i have an array, a double array like...

Double my_array = new Double[] {6272640.0, 43560.0, 4840.0, 0.0015625, 4046856422.400000095, 40468564.223999999, 4046.856422400, 0.004046856, 1.0, 0.404685642};

在我的程序中我想将每个元素乘以一些整数值...
我通过变量n接受。

and in my program i want to multiply each of that elements with some integer values... which i accept through a variable n.

我在我的程序中完成了...

i had done it in my program as...

for(int 1=0;i<my_array.length;i++)
{
my_array[i] = n*my_array[i];
}

当我尝试打印结果时,我获得指数值...
喜欢,3.23E等...... ......

when i try to print the result, i gets value as exponentials... like, 3.23E etc etc......

我需要将结果作为最多8位小数的双倍值...

I need the result as double value up to 8 decimal points...

我该怎么做才能得到它

推荐答案

我把我的双数组更改为字符串数组,如

I had changed my double array to String array, like

String my_array[];
my_array = new String[] {"1.006944444","6.45160645160", "0.00000326701", "0.0076001595"};

// then used my for loop like

BigDecimal b1 = new BigDecimal(n);
for(int 1=0;i<my_array.length;i++)
{
BigDecimal b2 = new BigDecimal(Double.parseDouble(my_array[i]));
BigDecimal result = b1.multiply(b2);
System.out.println(result.doubleValue);
}

请自行检查。正如我刚刚描述的那样,我的for循环还有很多工作要做..

just check it yourself. as i had just described the logic, my for loop had much more to do..

这篇关于双精度乘以精度和逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆