double

JTable cell text color changing

不打扰是莪最后的温柔 提交于 2020-01-30 06:34:27
问题 I´m rather new to Java and programming itself, so excuse me for the question. What I´m trying to do is the following: I´m making a bookkeeping program. On the column where the income/outcome is displayed, I want it so when the user enters a negative number (eg. -1.150€), the number turns red( or any color really, but red is what most bookkeeping programs use). only that specific cell on that column only. I have not started with a code yet so I cannot input one here. I also do not need it to

double pointers and 2d arrays in c

不想你离开。 提交于 2020-01-30 06:07:17
问题 I'm trying to access a 2D array using double pointer int x[2][2] = {{10, 20},{30, 40}}; int *xp; int **xpp; printf ("%d %d\n%d %d\n", x[0][0], x[0][1], x[1][0], x[1][1]); printf ("\n"); xp = *x; printf ("%d %d\n%d %d\n", *xp, *(xp + 1), *(xp + 2), *(xp + 3)); printf ("\n"); xpp = (int**)x; printf ("%d\n", **xpp); What I get is: 10 20 30 40 10 20 30 40 Segmentation fault Question: How should I access the array using xpp ? 回答1: Rather than ... int x[2][2] = {{10, 20},{30, 40}}; int **xpp; xpp =

c++ rounding of numbers away from zero

笑着哭i 提交于 2020-01-30 04:39:10
问题 Hi i want to round double numbers like this (away from zero) in C++: 4.2 ----> 5 5.7 ----> 6 -7.8 ----> -8 -34.2 ----> -35 What is the efficient way to do this? 回答1: inline double myround(double x) { return x < 0 ? floor(x) : ceil(x); } As mentioned in the article Huppie cites, this is best expressed as a template that works across all float types See http://en.cppreference.com/w/cpp/numeric/math/floor and http://en.cppreference.com/w/cpp/numeric/math/floor or, thanks to Pax, a non-function

Why is (long)9223372036854665200d giving me 9223372036854665216?

前提是你 提交于 2020-01-29 11:35:21
问题 I know about weird stuff with precision errors, but I can't fathom, Why is (long)9223372036854665200d giving me 9223372036854665216 ? 回答1: 9223372036854665200d is a constant of type double . However, 9223372036854665200 does not fit in a double without loss of precision. A double only has 52 bits of mantissa, whereas the number in question requires 63 bits to be represented exactly. The nearest double to 9223372036854665200d is the number whose mantissa equals 1

Why is (long)9223372036854665200d giving me 9223372036854665216?

妖精的绣舞 提交于 2020-01-29 11:35:06
问题 I know about weird stuff with precision errors, but I can't fathom, Why is (long)9223372036854665200d giving me 9223372036854665216 ? 回答1: 9223372036854665200d is a constant of type double . However, 9223372036854665200 does not fit in a double without loss of precision. A double only has 52 bits of mantissa, whereas the number in question requires 63 bits to be represented exactly. The nearest double to 9223372036854665200d is the number whose mantissa equals 1

Double increments in Java [duplicate]

一个人想着一个人 提交于 2020-01-29 07:09:30
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to iterate between 0.1f and 1.0f with 0.1f increments in Java? Part of my program needs to use values inside a while loop as: 0.1 0.2 0.3 ... 0.9 so I need to provide them inside that loop. Here is the code: double x = 0.0; while ( x<=1 ) { // increment x by 0.1 for each iteration x += 0.1; } I need the output to be EXACTLY: 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 But it actually gives me something like: 0.1 0.2

What exactly does Double mean in java?

佐手、 提交于 2020-01-28 04:29:30
问题 I'm extremely new to Java and just wanted to confirm what Double is? Is it similar to Float or Int? Any help would be appreciated. I also sometimes see the uppercase Double and other times the lower case double . If someone could clarify what this means that'd be great! 回答1: Double is a wrapper class, The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double. In addition, this class provides several methods

What exactly does Double mean in java?

笑着哭i 提交于 2020-01-28 04:28:48
问题 I'm extremely new to Java and just wanted to confirm what Double is? Is it similar to Float or Int? Any help would be appreciated. I also sometimes see the uppercase Double and other times the lower case double . If someone could clarify what this means that'd be great! 回答1: Double is a wrapper class, The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double. In addition, this class provides several methods

Double in place of Float and Float rounding

做~自己de王妃 提交于 2020-01-25 13:57:32
问题 Edit: This question covers two topics: The efficiency of using in double in place of float Float precision following rounding Is there any reason why I should not always use Java double instead of float? I ask this question because this test code when using floats is failing and not clear why since the only difference is the use of float instead of double. public class BigDecimalTest { @Test public void testDeltaUsingDouble() { //test passes BigDecimal left = new BigDecimal("0.99").setScale(2

Convert Hex to Double to Hex?

南楼画角 提交于 2020-01-23 17:42:50
问题 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