Tag: 浮点

在所有平台上,JVM上的浮点运算是否会得到相同的结果?

我在多台机器上运行的应用程序中使用Java,所有机器都需要得到相同的math运算结果。 使用Java的浮点基元是否安全? 还是应该使用定点math库?

将一个浮点数转换为一个string,而不是四舍五入

我正在做一个程序,由于不需要解释的原因,需要一个浮点数被转换成一个string来计算len()。 但是,str(float(x))导致x在被转换为string时被舍入,从而抛出整个事情。 有谁知道它的修复? 这里是使用的代码,如果你想知道: len(str(float(x)/3))

在mysql中存储金额

我想将3.50存储到一个MySQL表中。 我有一个float,我存储它,但它存储为3.5,而不是3.50。 我怎么能得到它的尾部零?

当我用clojure分数时,我得到一个分数,我怎么得到小数?

当我这样做的时候(/ 411 125) ,我不会用小数来表示。 我怎么做?

在Java中翻一番

我发现这个很好的解决方法: static Double round(Double d, int precise) { BigDecimal bigDecimal = new BigDecimal(d); bigDecimal = bigDecimal.setScale(precise, RoundingMode.HALF_UP); return bigDecimal.doubleValue(); } 然而,结果令人困惑: System.out.println(round(2.655d,2)); // -> 2.65 System.out.println(round(1.655d,2)); // -> 1.66 为什么给这个输出? 我正在使用jre 1.7.0_45。

在初始化“float”时,转换为“float”并添加“f”作为后缀,有什么区别?

有什么区别 float f = (float) 99.32 ; 和 float f = 99.32f ; 他们都编译并成功运行。

将string转换为整数/浮点在Haskell?

data GroceryItem = CartItem ItemName Price Quantity | StockItem ItemName Price Quantity makeGroceryItem :: String -> Float -> Int -> GroceryItem makeGroceryItem name price quantity = CartItem name price quantity 我想在使用String或[String]时创build一个GroceryItem, createGroceryItem :: [String] -> GroceryItem createGroceryItem (a:b:c) = makeGroceryItem abc input的格式是[“Apple”,“15.00”,“5”],我使用haskell中的单词函数进行分解。 我得到这个错误,我认为是因为makeGroceryItem接受一个浮点数和一个整数。 但是,我如何分别做b和c Float和Int? *Type error in application *** Expression : makeGroceryItem a read […]

将最小可能的浮点数添加到浮点数

我想将一个浮点数的最小可能值添加到浮点数。 所以,举个例子,我尝试这样做得到1.0 +最小可能的浮点数: float result = 1.0f + std::numeric_limits<float>::min(); 但是做完之后,我得到以下结果: (result > 1.0f) == false (result == 1.0f) == true 我正在使用Visual Studio 2015.为什么会发生这种情况? 我能做些什么来解决它?

浮点variables的范围会影响它们的值吗?

如果我们在控制台应用程序上执行下面的C#代码,我们会得到一条消息, The sums are Not equal 。 如果我们在取消注释System.Console.WriteLine()之后执行它,我们将得到一条消息,因为The sums are equal 。 static void Main(string[] args) { float f = Sum(0.1f, 0.2f); float g = Sum(0.1f, 0.2f); //System.Console.WriteLine("f = " + f + " and g = " + g); if (f == g) { System.Console.WriteLine("The sums are equal"); } else { System.Console.WriteLine("The sums are […]

将string转换为在C#中浮动

我正在转换一个string,如“41.00027357629127”,我正在使用; Convert.ToSingle("41.00027357629127"); 要么 float.Parse("41.00027357629127"); 这些方法返回4.10002732E + 15 。 当我转换为浮动我想要“41.00027357629127”。 这个string应该是一样的…