0

我需要插入System.Decimal通过java代码类型的变量。我尝试在java中使用float和double。但似乎它不接受。

任何想法是 java 中的数据类型与System.DecimalC# 中的数据类型等效。

谁能帮我吗?

4

3 回答 3

3

最好的等价物可能是BigDecimal。它不是任意精度而不是固定精度,System.Decimal而是精确的十进制算术。

于 2013-08-28T10:35:59.150 回答
1

Why do you need a C# System.Decimal in a Java application ????

Do you want an object instead of a primitive type float or double, then you have the class java.lang.Double. Using autoboxing of Java you can write code like

Double d = 0.3;

or not using autoboxing you can write

Double d = new Double(0.3);

if you have a String then you can use

Double d = Double.valueOf("0.3");

The class Double as an object class or the type double as primitive have the same properties regarding precision etc... if you want higher precision you can use the BigDecimal class.

BigDecimal bd = new BigDecimal("0.3");
于 2013-08-28T10:37:34.000 回答
0

I'm assuming you have a String and want to convert it into a format that supports decimal values...

String value = "12.34";
Float f = Float.valueOf(value);
于 2013-08-28T10:36:28.897 回答