double

string to double skips last decimal if it is zero?

廉价感情. 提交于 2019-12-17 21:17:10
问题 Here is my Problem. I need to Convert say "5.550" (string) to double as 5.550 that is double with 3 decimal digits. i have tried IFormatProvider while parsing but no use.it keeps skipping last zero(). Please advice. Thanks, Kumar M A 回答1: double doesn't keep insignificant digits - there's no difference between 1.5 and 1.50000 as far as double is concerned. If you want to preserve insignificant digits, use decimal instead. It may well be more appropriate for you anyway, depending on your exact

Why doesn't this sql query return any results comparing floating point numbers?

孤人 提交于 2019-12-17 20:57:38
问题 I have this in a mysql table: id and bolag_id are int . lat and lngitude are double . If I use the the lngitude column, no results are returned: lngitude Query: SELECT * FROM location_forslag WHERE lngitude = 13.8461208 However, if I use the lat column, it does return results: lat Query: SELECT * FROM location_forslag WHERE lat = 58.3902782 What is the problem with the lngitude column? 回答1: It is not generally a good idea to compare floating point numbers with = equals operator. Is it correct

Could not find an overload for '*' that accepts the supplied argument

家住魔仙堡 提交于 2019-12-17 19:24:01
问题 I have converted a String to an Int by by using toInt() . I then tried multiplying it by 0.01, but I get an error that says Could not find an overload for '*' that accepts the supplied argument. Here is my code: var str: Int = 0 var pennyCount = 0.00 str = pennyTextField.text.toInt()! pennyCount = str * 0.01 From reading other posts it seems that the answer has to do with the type. For example if the type is set as an Integer then it gets a similar error. I have tried changing the type to an

How to Convert Int number to Double number?

…衆ロ難τιáo~ 提交于 2019-12-17 18:48:32
问题 Using Javascript: How I can convert one number integer to Double Number Example: 100 -> 100.00 回答1: All numbers in JavaScript are doubles: that is, they are stored as 64-bit IEEE-754 doubles. That is, the goal is not to get a "double": the goal is to get the string reprsentation of a number formatted as "YYY.XX" . For that, consider Number.toFixed, for instance: (100).toFixed(2) The result is the string (not a "double"!) "100.00" . The parenthesis are required to avoid a grammar ambiguity in

Java signed zero and boxing

余生颓废 提交于 2019-12-17 18:27:44
问题 Lately I've written a project in Java and noticed a very strange feature with double/Double implementation. The double type in Java has two 0's, i.e. 0.0 and -0.0 (signed zero's). The strange thing is that: 0.0 == -0.0 evaluates to true , but: new Double(0.0).equals(new Double(-0.0)) evaluates to false . Does anyone know the reason behind this? 回答1: It is all explained in the javadoc: Note that in most cases, for two instances of class Double, d1 and d2, the value of d1.equals(d2) is true if

Android - Round to 2 decimal places [duplicate]

孤人 提交于 2019-12-17 17:27:14
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Round a double to 2 significant figures after decimal point I know that there are plenty of examples on how to round this kind numbers. But could someone show me how to round double, to get value that I can display as a String and ALWAYS have 2 decimal places? 回答1: You can use String.format("%.2f", d) , your double will be rounded automatically. 回答2: One easy way to do it: Double d; Int i; D+=0.005; i=d*100;

Inputting float into a program that only deals with ints

為{幸葍}努か 提交于 2019-12-17 17:00:31
问题 I have a program, but when I input float numbers whenever the program asks for inputs, the program abruptly skips a step and moves onto the end output. The program is below: #include <stdio.h> #include <stdlib.h> int main() { int a,b,c; int i; printf("Please enter a number: "); scanf("%d", &a); printf("Please enter a number: "); scanf("%d", &b); c = 0; for(i=0; i < b; i++) { c = c + a; } printf("%d x %d = %d\n", a, b, c); return 0; } When I input an int for a , and a float for b , the program

How to determine the max precision for double

99封情书 提交于 2019-12-17 16:57:11
问题 I am trying to determine what the maximum precision for a double is. In the comments for the accepted answer in this link Retain precision with double in Java @PeterLawrey states max precision in 15. How do you determine this ? 回答1: @PeterLawrey states max precision in 15. That's actually not what he stated at all. What he stated was: double has 15 decimal places of accuracy and he is wrong. They have 15 decimal digits of accuracy. The number of decimal digits in any number is given by its

double arithmetic and equality in Java

ⅰ亾dé卋堺 提交于 2019-12-17 16:56:08
问题 Here's an oddity (to me, at least). This routine prints true: double x = 11.0; double y = 10.0; if (x-y == 1.0) { // print true } else { // print false } But this routine prints false: double x = 1.1; double y = 1.0; if (x-y == 0.1) { // print true } else { // print false } Anyone care to explain what's going on here? I'm guessing it has something to do with integer arithmetic for int s posing as float s. Also, are there other bases (other than 10 ) that have this property? 回答1: 1.0 has an

Objective C Issue With Rounding Float

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-17 16:39:42
问题 I have an issue with rounding the result of a calculation to two decimal places. It is a financial calculation and when the result involves half a penny I would expect the number to be rounded up but it is in fact being rounded down. To replicate the issue: float raw = 16.695; NSLog(@"All DP: %f",raw); NSLog(@"2 DP: %.2f",raw); Returns: All DP: 16.695000 2 DP: 16.69 Whereas I would expect to see: All DP: 16.695000 2 DP: 16.70 Can anyone advise if this is by design or if (most likely) I am