double

Java Double Multiplication explanation? [duplicate]

▼魔方 西西 提交于 2019-12-08 17:23:03
问题 This question already has answers here : Moving decimal places over in a double (9 answers) Closed 6 years ago . I recently tested something out that I heard using the following code public static void main(String[] args) { double x = 4.35 * 100; System.out.println(x); } . I am interested as to why this produces 434.99999999999994 rather than 435.0 . Thanks 回答1: when you type double x = 4.35; x is not stored as-is. It is stored in a approaching form (probably 4.349999999 in this case). If you

How to round double values but keep trailing zeros

谁说我不能喝 提交于 2019-12-08 17:11:22
问题 In C# I want a function that rounds a given double to a given amount of decimals. I always want my function to return a value (which can be a string) with the given amount of decimals. If necessary, trailing zeros need to be added. Example: string result = MyRoundingFunction(1.01234567, 3); // this must return "1.012" That's easy, it's just rounding and converting to string. But here comes the problem: string result2 = MyRoundingFuntion(1.01, 3); // this must return "1.010" Is there a

C# Decimal.GetHashCode() and Double.GetHashCode() equal

旧城冷巷雨未停 提交于 2019-12-08 16:23:38
问题 Why is it that 17m.GetHashCode() == 17d.GetHashCode() (m=decimal, d=double) Additionally, as expected 17f.GetHashCode() != 17d.GetHashCode() (f=float) This appears to be true for both net3.5 and net4.0. As I understand, the internal bit representations of these types are quite different. So how come that the hash codes of decimal and double types equal for equal initialization values? Is there some conversion taking place before calculation of the hash? I found that the source code for Double

d programming, parse or convert string to double

自闭症网瘾萝莉.ら 提交于 2019-12-08 15:59:32
问题 as easy as it is in other languages, i can't seem to find an option in the d programming language where i can convert a string (ex: "234.32") into a double/float/real. using atof from the std.c.stdio library only works when i use a constant string. (ex: atof("234.32") works but atof(tokens[i]); where tokens is an dynamic array with strings doesn't work). how to convert or parse a string into a real/double/float in the d-programming language? 回答1: Easy. import std.conv; import std.stdio; void

Fastest way to check if a String can be parsed to Double in Java

ぃ、小莉子 提交于 2019-12-08 15:25:56
问题 I know there's a million ways of doing this but what is the fastest? This should include scientific notation. NOTE: I'm not interested in converting the value to Double, i'm only interested in knowing if it's possible. i.e. private boolean isDouble(String value) . 回答1: You can check it using the same regular expression the Double class uses. It's well documented here: http://docs.oracle.com/javase/6/docs/api/java/lang/Double.html#valueOf%28java.lang.String%29 Here is the code part: To avoid

C - Summation with Double - Precision

放肆的年华 提交于 2019-12-08 14:17:51
问题 I have problem with precision of double format . Sample example: double K=0, L=0, M=0; scanf("%lf %lf %lf", &K, &L, &M); if((K+L) <= M) printf("Incorrect input"); else printf("Right, K=%f, L=%f, M=%f", K, L, M); My test input: K = 0.1, L = 0.2, M = 0.3 -> Condition but goes to 'else' statement. How I can correct this difference? Is there any other method to summation? 回答1: In the world of Double Precision IEEE 754 binary floating-point format (the ones used on Intel and other processors) 0.1

std::numeric_limits<double>::digits10 = number of digits on the right or left to the radix point? [closed]

对着背影说爱祢 提交于 2019-12-08 14:12:23
问题 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 7 years ago . http://en.wikipedia.org/wiki/Double-precision_floating-point_format say that double can handle 16 digits of precision to the right part of the number, is digits10 show this number ? 回答1: Actually it's just the

SSIS Double Backslash is causing connection issues

梦想的初衷 提交于 2019-12-08 13:36:54
问题 I'm currently using an Execute SQL Task to pull in dynamic information to build my connection string for each of my databases. From there I'm passing them to a Foreach Loop. At this point I'm building my connection string using an expression: "Data Source="+ @[User::DatabaseServer]+ "\\"+@[User::Instance]+";User ID="+@[User::UserName]+ ";Password="+ @[User::Password] +";Initial Catalog=Defaul;Provider=SQLNCLI10.1;" My issue is the following, when my connection string is built with a double

How can you determine whether a double is an integer?

泄露秘密 提交于 2019-12-08 12:39:32
问题 Is there anyway in Swift 3 to determine whether a double value has decimal places or not? In my program, I only want to perform a calculation to this double if it is an integer value. How can I check to see if there's non-zero numbers after the decimal point? For example: let double dx = 1.0 // This would return true let double dy = 1.5 // This would return false Any and all help is appreciated! Thanks, Matthew 回答1: extension Double { var isInt: Bool { let intValue = Int(self) return Double

Division in c not giving expected value

本秂侑毒 提交于 2019-12-08 09:33:21
问题 When doing a division im getting a rounded answer? double div; div = 25/8; printf("%lf",div); When i do this prints out 3.0000 why dont i get 3.125 ? 回答1: Because you are doing an integer division, try with: div = 25.0/8; or div = (double)25/8; Typing 25.0 means a double literal. You could also use 25.f for a float literal. Both of these trigger floating point division. 回答2: Either typecast explicitly to double data type or change numerator to get desired value i.e. 25.o or use floating point