double

Convert Hex to Double to Hex?

南楼画角 提交于 2020-01-23 17:41:27
问题 In my project I have a QString with the hex value (Big Endian) QString hex_in("413DF3EBA463B0"); How could I convert hex_in to a rounded double? IEEE 754 (https://en.wikipedia.org/wiki/Double_precision_floating-point_format) 34.5 The user will edit the double and then my program needs to convert it back to hex. Thanks for your time :) 回答1: There is really only one way to do it, and that is to convert the string to an integer, put it in a union where you set an integer member and read out a

Java: many ways of casting a (long) Object to double

核能气质少年 提交于 2020-01-23 04:55:08
问题 I have an Object obj that I know is actually a long . In some Math code I need it as double . Is it safe to directly cast it to double? double x = (double)obj; Or should I rather cast it first to long and then to double. double x = (double)(long)obj; I also found another (less readable) alternative: double x = new Long((long)obj).doubleValue(); What are the dangers/implications of doing either? Solution Summary : obj is a Number and not a long . Java 6 requires explicit casting, e.g.: double

Java: double: how to ALWAYS show two decimal digits

我的梦境 提交于 2020-01-22 08:27:28
问题 I use double values in my project and i would like to always show the first two decimal digits, even if them are zeros. I use this function for rounding and if the value I print is 3.47233322 it (correctly) prints 3.47. But when i print, for example, the value 2 it prints 2.0 . public static double round(double d) { BigDecimal bd = new BigDecimal(d); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } I want to print 2.00! Is there a way to do this without using Strings?

Java: double: how to ALWAYS show two decimal digits

大憨熊 提交于 2020-01-22 08:27:26
问题 I use double values in my project and i would like to always show the first two decimal digits, even if them are zeros. I use this function for rounding and if the value I print is 3.47233322 it (correctly) prints 3.47. But when i print, for example, the value 2 it prints 2.0 . public static double round(double d) { BigDecimal bd = new BigDecimal(d); bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } I want to print 2.00! Is there a way to do this without using Strings?

why is the Double.parseDouble making 9999999999999999 to 10000000000000000? [duplicate]

狂风中的少年 提交于 2020-01-20 05:31:11
问题 This question already has answers here : How to resolve a Java Rounding Double issue [duplicate] (13 answers) Closed 6 years ago . why is the Double.parseDouble making 9999999999999999 to 10000000000000000 ? For Example : Double d =Double.parseDouble("9999999999999999"); String b= new DecimalFormat("#.##").format(d); System.out.println(b); IS Printing 10000000000000000 instead it has to show 9999999999999999 or 9999999999999999.00 Any sort of help is greatly appreciated. 回答1: double only has

How to check that IEEE 754 single-precision (32-bit) floating-point representation is used?

帅比萌擦擦* 提交于 2020-01-20 05:11:05
问题 I want to test the following things on my target board: Is 'float' implemented with IEEE 754 single-precision (32-bit) floating-point variable? Is 'double' implemented with IEEE 754 double-precision (64-bit) floating-point variable? What are the ways in which i can test it with a simple C program. 回答1: No simple test exists. The overwhelming majority of systems today use IEEE-754 formats for floating-point. However, most C implementations do not fully conform to IEEE 754 (which is identical

I want to know the difference between a long double and a double

岁酱吖の 提交于 2020-01-17 18:24:07
问题 For any algorithmic problem, an error of 10 -6 is allowed. I declared a long double as a variable in my first solution and got a WA. But, when I declared a variable as double , I got an AC. I want to know why this decision was made because long double is known to be more accurate than double . I have not changed anything except variables, output methods. Here is my code: #include <iostream> #include <string> #include <cmath> #include <vector> #include <queue> #include <deque> #include

Why does double.TryParse(“6E02”, out tempDouble) return true?

依然范特西╮ 提交于 2020-01-17 18:09:34
问题 It took me a day to figure out the problem that one of the if statement returns true for a string value. We are parsing to check whether the value is a number or a string. I found out that this statement used and when the string value comes in as 6E02 the statement return true that this is a double value. var double temp; var val ="6E02" result = double.TryParse(val, out temp) How can I fix this issue to return the result false for strings like (Number)E0(Number) Easy way I believe to check

Create a bitmap using double values instead of int Android

不羁岁月 提交于 2020-01-17 04:42:11
问题 In my code I need create a Bitmap using double values. It´s important use the correct value. I´m using: Bitmap bmp = Bitmap.createBitmap(int, int, Bitmap.Config.ARGB_8888); ... When i would need something like: Bitmap bmp = Bitmap.createBitmap(double, double, Bitmap.Config.ARGB_8888); Everything I've trying to make the conversion ( possible ? ) Only returns the initial value or integer How I can use double values ​​when creating the bitmap? 回答1: Perhaps I misunderstand the question, but

C printf float rounding

拜拜、爱过 提交于 2020-01-17 04:14:28
问题 I have to reimplement printf(3) with C without using any function that would do the conversion for me. I'm nearly done I just need %a and it's also nearly done thanks to you guys : How %a conversion work in printf statement? The man says: The double argument is rounded and converted to hexadecimal notation in the style[-]0xh.hhhp[+-]d, where the number of digits after the hexadecimal-point character is equal to the precision specification. So my question is rounded how ? I found: printf