double

The method println(double) in the type PrintStream is not applicable for the arguments (String, double)

末鹿安然 提交于 2019-12-11 05:05:15
问题 Here is the code: import java.util.Scanner; public class MoviePrices { public static void main(String[] args) { Scanner user = new Scanner(System.in); double adult = 10.50; double child = 7.50; System.out.println("How many adult tickets?"); int fnum = user.nextInt(); double aprice = fnum * adult; System.out.println("The cost of your movie tickets before is ", aprice); } } I am very new to coding and this is a project of mine for school. I am trying to print the variable aprice within that

Displaying doubles to a certain precision in java

折月煮酒 提交于 2019-12-11 04:40:44
问题 I am currently writing a calculator application. I know that a double is not the best choice for good math. Most of the functions in the application have great precision but the ones that don't get super ugly results. My solution is to show users only 12 decimals of precision. I chose 12 because my lowest precision comes from my numerical derive function. The issue I am having is that if I multiply it by a scaler then round then divide by the scaler the precision will most likely be thrown

Getting wrong answer in double arithmetic in Java [duplicate]

一世执手 提交于 2019-12-11 04:35:48
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Double calculation producing odd result I'm writing a program in Java that deals with a lot of double arithmetic. I eventually get to the point where I need to add 0.6666666666666666 and -0.666666666666667. However, the answer that I get is -3.3306690738754696E-16. In other words, double d1 = 0.6666666666666666; double d2 = -0.666666666666667; System.out.println(d1 + d2); prints out "-3.3306690738754696E-16".

Cannot convert from long to int, why can't I round this double to the nearest int using Math.round

﹥>﹥吖頭↗ 提交于 2019-12-11 04:21:09
问题 why can't I round this double to the nearest int using Math.round, I get this error "cannot convert from long to int" Double bat_avg = Double.parseDouble(data[4])/Double.parseDouble(data[2]); int ibat_avg = Math.round(bat_avg*1000.00); System.out.println(bat_avg); 回答1: You can use float instead: Float bat_avg = Float.parseFloat(data[4]) / Float.parseFloat(data[2]); int ibat_avg = Math.round(bat_avg * 1000.00f); System.out.println(bat_avg); There are two versions of Math.round : Math.round

Are there limits of precision on the memory capacity of double?

耗尽温柔 提交于 2019-12-11 03:32:58
问题 I'm reading an introductory book on Java and ran into something I don't quite understand. In covering variable types, the author states "the word double stands for numbers between This struck me as odd, since as written, it would include all numbers on the real number line between the two aforementioned limits. From my understanding, double is a primitive data type assigned 64 bits of memory. In turn, it's clear to me that 5.9 is a perfectly fine double, or float for that matter. However, I'm

C++ Bubble sorting a Doubly Linked List

混江龙づ霸主 提交于 2019-12-11 03:27:39
问题 I know bubble sort is probably not the fastest way to do this but its acceptable. i'm just having trouble with adjusting the algorithm to double link lists from arrays. My double linked lists have a type int and a type string to hold a number and a word. My list was sorted with an insertion sort that I wrote to sort alphabetically, now I need to reorder my double linked list numerically, greatest to least. My trouble spot is how to run this loop so that it is properly sorted thoroughly and

Incorrect VBA Overflow using Doubles (Excel)

假如想象 提交于 2019-12-11 03:19:23
问题 For some reason, the following statement evaluates to zero. I assume it's due to overflow, but all the interim values seem to be well within the limits of a double. DiffieHellmanKey = (43 ^ 47) - (53 * Fix((43 ^ 47) / 53)) I think it's overflow because when I execute it with different numbers (below), it results in the correct value of 29. DiffieHellmanKey = (5 ^ 22) - (53 * Fix((5 ^ 22) / 53)) What gives? Now, back to the original numbers that are giving me overflow. All variables involved

Long accumulator instead of Double in MongoDB group() function

廉价感情. 提交于 2019-12-11 03:00:18
问题 I am using MongoDB via official Java API. I can store and retrive Long values without any extra effort. But when I try to accumulate these values using group() function, JavaScript interpreter converts everything into Doubles and the final result ends up being a Double. Here is my group command: { ... initial: { count: 0 }, reduce: "function (o, a) { a.count += o.count; }" } Is there a way to tell the interpreter that count is in fact a Long? Something like count: 0L or count: Long(0) ? Or

Overloading Primitive Operator (C#)

丶灬走出姿态 提交于 2019-12-11 02:57:45
问题 Is there a way I can overload primitives, for example addition with doubles? I want to automatically round the doubles whenever an operation is performed. My current code is this: class Test{ public static double operator +(double x, double y){ return Math.Round(x + y) } } but there's an unfortunate error that says "One of the parameters of a binary operator must be the containing type". 回答1: You can't overload operators on primitive types. This would cause havoc in your codebase. What you

Can all 32 bit ints be exactly represented as a double? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-11 02:56:07
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Which is the first integer that an IEEE 754 float is incapable of representing exactly? This is basic question, my feeling is that the answer is yes(int = 32 bits, double = 53 bit mantisa + sign bit). Basically can asserts fire? int x = get_random_int(); double dx = x; int x1 = (int) dx; assert(x1 ==x); if (INT_MAX-10>x) { dx+=10; int x2=(int) dx; assert(x+10 == x2); } Obviously stuff involving complicated