double

How do I round a double to one decimal place? [closed]

人盡茶涼 提交于 2019-12-22 18:19:47
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I am trying to get a random double returned to me in the format #.# however I am getting a value of something to this effect: 0.9395772067578356 How do you force only a one decimal return on a random double as I

Rounding a double number up to the tenths place [duplicate]

眉间皱痕 提交于 2019-12-22 17:53:32
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: round() for float in C++ Ok suppose I had the number 8.47434 . I want to round it up to 8.5 and to 1 decimal place. How would I go about doing this in C++ 回答1: Multiply by 10 , round and divide by 10 again. Example: round(10 * 8.47434f) / 10; Edit: OK, I just found out that round() is not always present in math.h . The above works in gcc and icl (with Microsoft's libraries), but not in tcc. floor() , however, is

Laravel Eloquent double value stored in database returned rounded

心已入冬 提交于 2019-12-22 13:33:16
问题 I have following value stored in MySQL database 23456789123,45678 and when I'm getting this value using magic variable I'm getting 23456789123,457 as a value. I have tried $cast variable in Model: protected $casts = [ 'previous_value' => 'double(16,5)', ] but that did not helped. Much appreciate on any help in this regards. 回答1: The problem is not with Laravel, it is actually PHP that is rounding this. In the PHP documentation you can see that the default precision is 14 , which you are

BigDecimal - check value is within double range

ε祈祈猫儿з 提交于 2019-12-22 12:58:16
问题 I have a Java application which parses a number from somewhere, and checks that it is a valid int (between Integer.MIN_VALUE and Integer.MAX_VALUE) or a valid double (between Double.MIN_VALUE and Double.MAX_VALUE). I'm using this code: import java.math.BigDecimal; import java.math.BigInteger; public class Test { public static final BigDecimal DOUBLE_MAX = BigDecimal.valueOf(Double.MAX_VALUE); public static final BigDecimal DOUBLE_MIN = BigDecimal.valueOf(Double.MIN_VALUE); public static final

how to handle culture in double parsing in c#?

二次信任 提交于 2019-12-22 11:26:12
问题 I have a question about how to handle culture while parsing doubles. In a system price information from various servers comes together. However the data thats given as input varies in culture. two million and fifty cents is given as : "2.000.000,50" "2,000,000.50" "2000000.50" "2000000,50" is there a generic way to handle these various types of input ? 回答1: No, there is no generic way. You either need to know what culture the double was formatted or all the servers need to send in a single

Choosing an Epsilon Value for Floating Point Comparisons

谁说我不能喝 提交于 2019-12-22 11:05:10
问题 My team is working with financial software that exposes monetary values as C# floating point doubles. Occasionally, we need to compare these values to see if they equal zero, or fall under a particular limit. When I noticed unexpected behavior in this logic, I quickly learned about the rounding errors inherent in floating point doubles (e.g. 1.1 + 2.2 = 3.3000000000000003). Up until this point, I have primarily used C# decimals to represent monetary values. My team decided to resolve this

Getting the fractional part of a double value in integer without losing precision

霸气de小男生 提交于 2019-12-22 10:36:43
问题 i want to convert the fractional part of a double value with precision upto 4 digits into integer. but when i do it, i lose precision. Is there any way so that i can get the precise value? #include<stdio.h> int main() { double number; double fractional_part; int output; number = 1.1234; fractional_part = number-(int)number; fractional_part = fractional_part*10000.0; printf("%lf\n",fractional_part); output = (int)fractional_part; printf("%d\n",output); return 0; } i am expecting output to be

Matlab - Undefined Error for Input Arguments of Type Double [duplicate]

穿精又带淫゛_ 提交于 2019-12-22 10:27:31
问题 This question already has answers here : “Undefined function 'function_name' for input arguments of type 'double'.” (3 answers) Closed 3 years ago . I'm trying to write a function that does what conv2(h1,h2,A) & conv2(...'shape') does without using the built-in function. (speed is currently not an issue). as defined here: http://www.mathworks.co.uk/help/matlab/ref/conv2.html These are my commands: imgC = imread('camerman.tif'); imgC = double(imgC); sigma = 1; inp = (-1 .*2.5 .*sigma):1:(2.5 .

How to get the double value using libpq?

故事扮演 提交于 2019-12-22 10:00:04
问题 The examples in the libpq documentation show how to get the the integer value by converting it to the host-endian representation. I am curious what must be done to get the double precision value using libpq (without libpqtyppes)? I have tried reinterpret_cast with no luck. Also why text and byte data doesn't need endian conversions? The DB runs locally on Windows 7, I am using Visual C++ 2013. pptr is a double vaule I am trying to retrieve. #include <iostream> #include <memory> #include

Converting a precision double to a string

别等时光非礼了梦想. 提交于 2019-12-22 09:21:50
问题 I have a large number in c++ stored as a precise double value (assuming the input 'n' is 75): 2.4891e+109 Is there any way to convert this to a string or an array of each individual digit? Here's my code so far, although it's not entirely relevant to the question: int main(){ double n = 0; cout << "Giz a number: "; cin >> n; double val = 1; for(double i = 1; i <= n; i++){ val = val * i; } //Convert val to string/array here? } 回答1: std::stringstream str; str << fixed << setprecision( 15 ) <<