double

Why in this Java program the Doubles in a String Output have too many decimals?

那年仲夏 提交于 2020-01-07 08:36:08
问题 In a solution to an exercise in the Book Art and Science of Java I had to write a program that converts Kilograms into the corresponding values in Pounds and Ounces. I wrote the program but when I try to convert say 1kg, the result the program gives me is: 1 kg = 2 pounds and 3.200000000000006 ounces Now my constants are 2.2 pounds per kg and 16 ounces per pound so 3.2 ounces is correct. But not with so many 0's and that 6 at the end freaks me out. Anyone know why this happens and how it can

How to default an EditText to integer but allow decimal input?

江枫思渺然 提交于 2020-01-07 05:37:13
问题 I am using an EditText to allow a user to input a value that is stored in a Double. However, by default, Doubles look like "0.0" and it's a little annoying for a user to backspace over the extra decimal if it's not used. Is there a way to force-display whole numbers to look like "0" and only show the decimal if the user actually decides to use it? Current code: myEditText = (EditText) view.findViewById(R.id.my_edittext); myEditText.setText(myVariable + ""); myEditText.addTextChangedListener

CultureInfo and Double.parse and double.toString not worked correctly

为君一笑 提交于 2020-01-07 04:20:28
问题 How can I force c# application to use . for decimal separator and ignore culture settings in server. I have this problem with double.ToString and double.parse I should change setting in application level because of large scale of application. exception occurse in case like double.parse("1/25") and 1.25 ToString I have Try This code string CultureName = Thread.CurrentThread.CurrentCulture.Name; CultureInfo ci = new CultureInfo(CultureName); if (ci.NumberFormat.NumberDecimalSeparator != ".") {

Atomic operations with double, OpenCL

拈花ヽ惹草 提交于 2020-01-06 16:22:12
问题 I would like to know if there's a way to implement atomic operations (particularly atomic_add) with double type. For floats this code works, but atomic_xchg doesn't support double: while ((value = atomic_xchg(addr, atomic_xchg(addr, 0.0f)+value))!=0.0f); 回答1: I was looking for for the same in the past and I found this: https://github.com/ddemidov/vexcl-experiments/blob/master/sort-by-key-atomic.cpp. At the end I figured out different approach to my problem so I did not use it. Here is the

Atomic operations with double, OpenCL

六月ゝ 毕业季﹏ 提交于 2020-01-06 16:19:16
问题 I would like to know if there's a way to implement atomic operations (particularly atomic_add) with double type. For floats this code works, but atomic_xchg doesn't support double: while ((value = atomic_xchg(addr, atomic_xchg(addr, 0.0f)+value))!=0.0f); 回答1: I was looking for for the same in the past and I found this: https://github.com/ddemidov/vexcl-experiments/blob/master/sort-by-key-atomic.cpp. At the end I figured out different approach to my problem so I did not use it. Here is the

Why I can't call Math.Round(double,int) overload

醉酒当歌 提交于 2020-01-06 11:00:21
问题 In .NET Library there is Function like System.Math.Round(double, int) But why I need to cast double value to float to make it work..?? Look on the following screenshot: 回答1: The following function Math.Round(double value, int digits) Returns a double . I see that you have tried to define a float of name d to the output from Math.Round(n,2) where n is a double of value 1.12345 and 2 represents an integer using the following code double n = 1.12345; float d = Math.Round(n,2); You'll actually

Why I can't call Math.Round(double,int) overload

余生颓废 提交于 2020-01-06 10:58:28
问题 In .NET Library there is Function like System.Math.Round(double, int) But why I need to cast double value to float to make it work..?? Look on the following screenshot: 回答1: The following function Math.Round(double value, int digits) Returns a double . I see that you have tried to define a float of name d to the output from Math.Round(n,2) where n is a double of value 1.12345 and 2 represents an integer using the following code double n = 1.12345; float d = Math.Round(n,2); You'll actually

How accurate is “double-precision floating-point format”?

老子叫甜甜 提交于 2020-01-06 05:25:32
问题 Let's say, using java, I type double number; If I need to use very big or very small values, how accurate can they be? I tried to read how doubles and floats work, but I don't really get it. For my term project in intro to programming, I might need to use different numbers with big ranges of value (many orders of magnitude). Let's say I create a while loop, while (number[i-1] - number[i] > ERROR) { //does stuff } Does the limitation of ERROR depend on the size of number[i]? If so, how can I

Getting rid of double quotes inside array without turing array into a string [closed]

被刻印的时光 ゝ 提交于 2020-01-06 03:55:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have an array x=["1", "2", "3", ":*", ":+", "4", "5", ":-", ":/"] I'm trying to get rid of the double quotation inside of the array. I know I can use: x.to_s.gsub('"','') and it will output a string: "[1, 2, 3, :*, :+, 4, 5, :-, :/]" The desired output I want is an array not a string: [1, 2, 3, :*, :+, 4, 5, :

format a double to 8 decimal places

♀尐吖头ヾ 提交于 2020-01-06 03:35:13
问题 I have a method that i want to return as a double with 8 dp. so i have a value coming back from a sp and in the code i am simply doing CheckSum = double.Parse(cmd.ExecuteScalar().ToString()); however, if the sp returns this :1541338.2349537 the returned double only has those 7dp, when i would like it to put a trailing zero on. like this.. 1541338.23495370 i cant find a method on the double to format it - ie force it to 8dp, other than to return a formatted string. which i dont want to do. can