double

Why would you use float over double, or double over long double?

时光毁灭记忆、已成空白 提交于 2019-12-09 08:21:47
问题 I'm still a beginner at programming and I always have more questions than our book or internet searches can answer (unless I missed something). So I apologize in advance if this was answered but I couldn't find it. I understand that float has a smaller range than double making it less precise, and from what I understand, long double is even more precise(?). So my question is why would you want to use a variable that is less precise in the first place? Does it have something to do with

Convert double into hex in C#

旧巷老猫 提交于 2019-12-09 08:03:43
问题 I have this value: double headingAngle = 135.34375; I would like to convert it to HEX and print the HEX to the console. I have already converted a string and int into their respective HEX values, but a double seems to be much more tricky. Can someone point me in the right direction? 回答1: Well, I googled for a minute or two and according to this here is a quite ellegant solution double d = 12.09; Console.WriteLine("Double value: " + d.ToString()); byte[] bytes = BitConverter.GetBytes(d);

storing a string arraylist into a double arraylist?

那年仲夏 提交于 2019-12-09 07:05:17
问题 I have a string arraylist with numbers like ["51,073","51,074","51,073"] now i want to convert this into a Double ArrayList and calculate the sum of the numbers in the array list. Here is the code : private ArrayList<String> totals = new ArrayList<>(); private ArrayList<Double> demototal = new ArrayList<>(); String total = itemData.getString(ParseBarcode.KEY_TOTAL); totals.add(total); /*converting all values from totals array to Double and add to arraylist demototal*/ for (int i = 0; i <

JSF 2.0 and Multiple Submission problem

隐身守侯 提交于 2019-12-09 07:03:34
问题 Somebody told me that JSF 2.0 automatically handles multiple submission problem. Is that right? If yes, how does JSF 2.0 do that? If no, what are the things that must taken care of, so that you don't leave any pitfall while handling this problem? Thanks. 回答1: This is requested and maintained by JSF spec issue 559. As it currently stands, it's not there yet, but it is targeted for the upcoming JSF 2.2. Until then, the Seam's <s:token> is your best solution which not only prevents CSRF (which

How to properly display a price up to two decimals (cents) including trailing zeros in Java?

左心房为你撑大大i 提交于 2019-12-09 06:08:06
问题 There is a good question on rounding decimals in Java here. But I was wondering how can I include the trailing zeros to display prices in my program like: $1.50, $1.00 The simple solution of String.format("%.2g%n", 0.912385); works just fine, but omits the trailing zero if it is at the last decimal place. The issue comes up in my program even though I only use expressions like this: double price = 1.50; When I do calculations with different prices (add, multiply, etc.) the result is primarily

JsonConvert throws a 'not a valid integer' exception when deserializing to a double

亡梦爱人 提交于 2019-12-09 05:49:30
问题 I get an exception when I try to deserialize to an object from a JSON string. Input string '46.605' is not a valid integer. Path 'LatitudeCenter' It's really weird because JsonConvert tries to deserialize an attribute as an integer but it actually is a double and not an integer . I already checked in my Web API project. The attribute in my class is a double and same in web project. The code I use in my web asp project: using (var client = new HttpClient()) { client.BaseAddress = new Uri(

Comparing doubles in Java gives odd results

断了今生、忘了曾经 提交于 2019-12-09 04:44:44
问题 I really can'get my head around why the following happens: Double d = 0.0; System.out.println(d == 0); // is true System.out.println(d.equals(0)); // is false ?! This however works as expected: Double d = 0.0; System.out.println(d == 0.0); // true System.out.println(d.equals(0.0)); // true I'm positive that this is related to autoboxing in some way, but I really don't know why 0 would be boxed differently when the == operator is used and when .equals is called . Doesn't this implicitly

Round Up a double to int

狂风中的少年 提交于 2019-12-09 03:30:59
问题 I have a number ("double") from int/int (such as 10/3). What's the best way to Approximation by Excess and convert it to int on C#? 回答1: Are you asking about System.Math.Ceiling? Math.Ceiling(0.2) == 1 Math.Ceiling(0.8) == 1 Math.Ceiling(2.6) == 3 Math.Ceiling(-1.4) == -1 回答2: int scaled = (int)Math.Ceiling( (double) 10 / 3 ) ; 回答3: By "Approximation by Excess", I assume you're trying to "round up" the number of type double. So, @Doug McClean's "ceiling" method works just fine. Here is a note

converting string to a double variable in C

倖福魔咒の 提交于 2019-12-09 02:53:06
问题 I have written the following code....It should convert a string like "88" to double value 88 and print it void convertType(char* value) { int i = 0; char ch; double ret = 0; while((ch = value[i] )!= '\0') { ret = ret*10 +(ch - '0'); ++i; } printf("%d",ret);//or %f..what is the control string for double? } //input string :88 But it always prints 0...But when i change type of ret to int ...it works fine...when the type is float or double,it prints zero...so why am i getting this ambiguous

IEEE double such that sqrt(x*x) ≠ x

空扰寡人 提交于 2019-12-09 02:33:00
问题 Does there exist an IEEE double x>0 such that sqrt(x*x) ≠ x , under the condition that the computation x*x does not overflow or underflow to Inf , 0 , or a denormal number? This is given that sqrt returns the nearest representable result, and so does x*x (both as mandated by the IEEE standard, "square root operation be calculated as if in infinite precision, and then rounded to one of the two nearest floating-point numbers of the specified precision that surround the infinitely precise result