I'm trying to make a simple GUI program without using JComponents. Currently, I have a BufferedImage that I draw to off screen so that it doesn't flicker (or so I thought). I made a new program here to replicate the issue: package Main; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import...

I have a silly problem. Let's say I have certain double number: double doubleValue=4.1; Is there a way to present this value as 4.10 but not as String but rather as double?...

I'm using MinGW on windows 7 to compile C files. My problem is a strange behaviour with scanf() to read doubles from user input. My code: int main() { double radius = 0; double pi = 3.14159; scanf("%lf \n", &radius); // after the input, it continues waiting... radius = ((radius...

How Can we have a double digit drop downs for minutes and hours selection, in rails forms? i checked the range drop downs in rails, but it is generating single digit numbers in drop down like 0, 1, 2 etc,but i wanted to generate these numbers like 00, 01,02 etc.,

Program: User enters a file name containing numbers (1 per line) File is read and data is stored in StringBuffer StringBuffer is converted to String type String is split() and stored in a String[] Double[] is created and converts/stores elements of the String[] The above is what I am trying...

I had a two field validator working without the composite as follows public class DoubleMustBeGreaterThanSecondDouble implements Validator { @Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { Double firstDouble = (Double) value; Double secondDouble = (Double) component.getAttributes().get("secondDouble"); if (firstDouble <= secondDouble) { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,...

I have found this vise-versa many times on SO, but never like I want it. I want to convert a double into a string that takes up exactly n characters. If n is, for example, 6, then 1,000,123.456 would become 1.00E6 -1,000,123.456 would become 1.0E-6 1.2345678 would become 1.2345 1,000,000,000,000...

I have a visitors count in my website and I'm trying to save it as Double instead of Integer because it allows higher numbers. The thing is that when the count is too high, for instance 300,000,000,000,000,000,000,000, it gets saved as 3.0E+23. How can I possibly parse this number to...

I'm currently writing a program that needs to take the floor of a square root. Since the value I'm taking the square root of is positive, I just cast it to int. So say for the following example: int i = 16; int j = std::sqrt(i) j should be 4....

I just read about the IEEE 754 standard in order to understand how single-precision and double-precision floating points are implemented. So I wrote this to check my understanding: #include <stdio.h> #include <float.h> int main() { double foo = 9007199254740992; // 2^53 double bar = 9007199254740993; // 2^53 + 1 printf("%d\n\n",...

I have a double value and I want to shorten it to 6 digits after the integer part. For example: double aDouble = 418.73684210526318; double convertedDouble = conversion (aDouble); convertedDouble must be 418.736842 I implemented this solution: convertedDouble = floor(aDouble * 1000000) / 1000000; However, convertedDouble is 418.73684200000002, not 418.73684200000000...

I have the following Problem. I want to concat a String with an DoubleBinding to an String property. Slider slider = new Slider(1, 5000, 500); Label sliderValue = new Label(); sliderValue.textProperty().bind(Bindings.concat("Sleep: ", slider.valueProperty())); This is working fine. But I don't want to display the Double Binding as an Double, I...

In c++ we can write something like float f = 3.55; and it is a legal statement. whereas the type of real number numerals is double and we are storing that double into floating point number. It essentially means storing 8 bytes into 4 bytes (a possible data loss)? My...

I'm creating an Android app and I need to calculate the movement speed of the device. I do this by taking an average of some earlier locations' speeds. However, I need the speed to be in km/h as an int, so I use (int)Math.ceil(speedAsDouble) However, this always equal to 1,...

This question already has an answer here: Is floating point math broken? 18 answers Why not use Double or Float to represent currency? 10 answers I am working on a project where we are calculating prices of items with 8 places of decimal points. But sometime calculation results are...

is there a php function other than is_numeric that determines if a variable is a number(not hex). Because i a need to verify if a variable is a number/decimal, no hex or other type of numericals that have letters in them.

I need the area method that contains the formula for the area of a circle to take in the radius that was found by the other area method that calculated the distance...So one of the area methods calculated the distance/radius then I want that answer to be used in the...

This question already has an answer here: How can I pad an int with leading zeros when using cout << operator? 6 answers In a C++ program, I want to display a column of floating point values so that the sign, digits, and decimal point all line up. Multiple...

I've got a problem with precision. I am multiplying a lot of really low numbers like 0.000001 by each other a lot of times (sometime around 500-1000) and thus I am losing precision. I've got my numbers in double (in dictionary as well). Is there a way to fix this?...

I have a program which multiplies a probability over 500 times, but when I am doing so the output is zero. Should I use some other data type? Please help. Here is the code I am using: double d = 1/80000d; for (int i = 0; i < 500; i++)...

I have a double ex: -2.34 I want to add 9 zeros in front of it to make length fixed to 10 digits. Result: -0000000002.34 I tried: String formatted = String.format("%010d", number); But can we pass a double to the String format function? What is the most efficient method to...

I have some code to convert the datatypes of some of the columns of a datagridview into a double, as they should be displaying as currency in my grid view. However when I run the code, the values are still displayed as a normal decimal. Am I using the wrong...

Suppose that we have this code: a = pi; b = pi+2; c = pi*2.2 out = [a b c] returns: out = 3.1416 5.1416 6.9115 I want this output (without rounding values to two decimal): out = 3.14 5.14 6.91 I don't want print these values. I want see...

So I have an unsigned integer Q with the value of 0xfccd11c0. When I print it with printf("%i", Q); I get -53669440 which is the signed integer representation of 0xfccd11c0 so I get it. But when I print it with printf("%i", (double)Q); I get 939524096. I DO know that in...

I wrote a simple java program that outputs what your weight would be on the moon. The following code class MoonWeight { public static void main(String args[]) { double earthWeight = 195.0; double moonWeight = earthWeight*.17; System.out.println("On Earth you weigh " + earthWeight + ", on the moon you weigh...

I have a text file that I want to read using C. It contains lines in this format: %d %d (%d or %lf). An example of 3 lines: 1 0 44 2 0 84.13 3 1 15.07 But the last number can be either int or double, arbitrary. How can...

I wrote this code in MIPS to calculate the sum of N-numbers with double float precision. But when I print the result it prints 0.00000 althought I see that in memory it's the correct result. Anyone can help me with this? #architecture ex.2 .data first: .asciiz "Give the number of...

I'm a beginner in Java programming. When I coded a simple console app it gave an output which was not what I wanted. My code is: class myClass{ public static void main(String[] args) { int ballsPlayed = 100; double o = (double)(( ballsPlayed / 6 ) + ( ( ballsPlayed...

hi i am new to MVC and i am trying to use Remote Data annotation with additional fields to validate Name and last name. everything is working great but i am getting double error messages when the name and lastname already exists. how can i fix this problem? This is...

I need to create a program that will prompt the user to enter salaries and get the highest and lowest salaries.. Ive been working on it for 4 days now.. and I finally created my program using some of the tutorials on the internet but I only have one problem......

I want to create a function, which has parameters with value, decimal mark and number of digits after decimal mark. This function will convert double value to string with given parameters. Here is the function I created. public static string ConvertDoubleToString(double value, string decimalMark = ".", int decimalDigits = 2)...

From the C++11 header , I was wondering if a std::uniform_real_distribution<double> object can spit out a double that's greater than 0.99999999999999994? If so, multiplying this value by 2 would equal 2. Example: std::default_random_engine engine; std::uniform_real_distribution<double> dist(0,1); double num = dist(engine); if (num > 0.99999999999999994) num = 0.99999999999999994; int test1 =...

This question already has an answer here: JUnit assertEquals( ) fails for two objects 2 answers Let's say I've got my own class Point with double X, double Y; public class Point { private final double x; private final double y; public Point(double x, double y) { this.x =...

I have two arrays of double values called lat2[] and lon2[]. I have there stored the particular lattitude and longtitude values. And I can get those values as simple double values. My question is how can I find if this two doubles exist in the array (to check which marker...

I was trying to write a program that calculates the time it takes for any sum of money to double at a given rate of interest compounded annually. When I run this program, I have found that the loop is not exiting the counter is incremented endlessly with the sum...

Say I have a string s = '128.0' and I want to convert it to double, I am trying to use: news = str2double(s); But the value of s is becoming 128. I want the str2double function to recognize the decimal point as part of the number. Any way to...

I am having trouble parsing "1,234.56" in Java, a similar question recommend using French locale in number formatting, but it is parsing the result incorrectly. Here is what I have: NumberFormat format = NumberFormat.getInstance(Locale.FRANCE); Number number = format.parse("1,234.56"); System.out.println(number.doubleValue()); // Should get 1234.56, got 1.234 instead Number number = format.parse("1,234,567.89");...

As stated in the documentation of Postgres 9.0 the double precision data type has a precision of 15 decimal digits and a storage of 8 bytes, then an integer number larger than a normal bigint (8 bytes) stored in a double precision field is approximated. Correct me if I'm wrong,...

I have an app where the user can enter an amount into an EditText but then I want to be able to add or subtract this to/from a double then be able to display this double with a TextView within another activity. I'm not sure how to go about this...

im pretty new at this whole java/android coding so i was seeking help from the more experienced. Would you happen to know why my app keeps crashing when i hit back space for the editText tag. I believe its because of the double and when the content goes to backspaces...

private void createNewMemberCheckInRecord(){ int row = bookingTable.getSelectedRow(); if(row<0){ JOptionPane.showMessageDialog(null, "Please choose a booking","ERROR",JOptionPane.ERROR_MESSAGE); } else{ final String roomType = ((BookingTableModel)bookingTable.getModel()).getValueAt(row,3).toString(); ============================================================= final double totalPrice = (Double.parseDouble((BookingTableModel)bookingTable.getModel()).getValueAt(row,9).toString());...

This question already has an answer here: How to round a number to n decimal places in Java 17 answers public double hypotenuse() { //return Math.hypot(leg, leg); //returns 7.0710678118654755 //return 0.1 * Math.floor(Math.hypot(leg, leg) * 10); //returns 7.0 //return 0.1 * Math.ceil(Math.hypot(leg, leg) * 10); //returns 7.1000000000000005 return 0.1...

This is my sample dictionary: { "gross_price" = "6.5678565676"; "gross_price_total" = "6.00"; } Now I parse that values: if let grossPriceTotal = dictionary["gross_price_total"] as? Double { order!.grossPriceTotal = grossPriceTotal //doesn't work } if let grossPriceTotal = dictionary["gross_price"] as? Double { order!.grossPriceTotal = grossPriceTotal //works } Why the first conditional is...

I need to deal with very large matrices and/or large numbers and I don't know why double result = 2251.000000 * 9488.000000 + 7887.000000 * 8397.000000; gives me the correct output of 87584627.000000. Same with int result. However, if I use float result = 2251.000000f + ... etc, it gives...

The functions purpose is to calculate the square root of a number using the Newton-Raphson method. I included a printf routine in the while loop so I can see the value of root 2 get closer and closer to the actual value. I originally used float to define epsilon but...

In Effective Java there is an example of Complex class. That class has overridden hashCode which uses hashDouble method I have a question about. private int hashDouble(double val) { long longBits = Double.doubleToLongBits(re); return (int) (longBits ^ (longBits >>> 32)); } For what purpose it does (int) (longBits ^ (longBits...

I implemented the same algorithm both on CPU and GPU using C++ and CUDA C. In order to check if the results are correct I check if the 2 arrays of double calculated by both are the same with a precision of 1.0E-8 . And the result is that the...

This question already has an answer here: Why are these numbers not equal? 3 answers I am running the code below. The function Ax returtns the value 1. But the ifelse statement does not recognize that Ax==1. I've tried making the output of the function double-precision and all numeric...

I'm a newbie, and a bit of a regex dullard, so please forgive me what will appear to be a completely stupid question. In PHP I'm trying to use a regex to match when a double quote " appears in text from a control on an HTML form and allow...

So I am having problem with a method I created, called averageCost(). The error I get is: Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method doubleValue() is undefined for the type Double at queue.averageCost(queue.java:38) at queue.main(queue.java:47) And previously I tried just adding a double value to a Double...

There is a way to validate a double number in the current culture? I have tried this: var number ="10,10"; double value = double.Parse(number, NumberStyles.Float, CultureInfo.CurrentCulture); If I try this with "es-ES" (where decimal separator is ",") then the parsing works perfect, I got an double 10.10, but if I...

This question already has an answer here: Difference between declaration and malloc 8 answers Let assume that I want to get space for an array of x double, x being an integer. Can someone explain me the difference between double myArray[x]; and malloc(x*sizeof(double)); excepted the fact that malloc() returns...

I have a file containing double precisions written from a FORTRAN code in the format of x.yyyyD+zz. When using read.csv in R, R does not seem to recognize those as floating point values. I'm new to R; what's the trick here?

Is this the right way to convert a microseconds and represent it as a timeval in my application ? I require the usage of a struct timeval and the above code is part of a routine that converts a double microsecond to a timeval NEGATIVE Value in this code //UPDATE...

I have a double variable assigned to a boundfield in a gridview. There will only ever be a max of 5 decimal places. The boundfield is formatting the display to a scientific value. I'm assuming because it would default to a general format which gives the most compact of either...

I am trying to build a finantial application that handle economical data using Matlab. The file I want to load is in a csv file and are double numbers in this format '1222.3'. So far, I am just working with one dimension and I am able to load the data...

I am writing a code for my Java class that calls for me to create something that looks like a bill/receipt. similar to: Item quantity price total gum 10 $1.49 $14.90 soda 3 $1.00 $3.00 chips 20 $1.25 $20.00 I am using the printf(); method. The variables i have declared...

class simple { public static void main() { double n, m; Scanner ip = new Scanner(System.in); n = ip.nextDouble(); m = ip.nextDouble(); m = n * m; System.out.println("Value in " + m); } } In the above code.. My output should only use decimal poinf if my input is using...

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...

I'm working on a clustering program, and have a dataset of doubles that I need to normalize in order to make sure that every double (variable) has the same influence. I would like to use min-max normalization where for every variable the min and max value are determined, but I'm...

I'm having trouble figuring out when to use int, double and long. I'm working on calculating the power of an integer and return the result as long as the power provided is not a negative number. For the assignment, I'm required to use the following code to start: public static...

The error on this line is Type mismatch: cannot convert from boolean to double The thing is all the values im calculating are doubles, I'm really confused. if(price == minprice < .20 * minprice){ Its been a few years since I last programmed in Java so sorry if this is...

Double.parseDouble is causing my program to throw some NullPointerExceptions. Is there any way I can convert a String to a double without using the .parseDouble method? I know String.format() can be used for Double to string, but is there something similar for the other way around? EDIT: try { if(amountEntered...

Doing function that takes 2 arrays (column1 and column2) from struct CSV D and plots the graph from it. Idea is to find max, min values of each array, then break range between min−EPSILON and max+EPSILON in to 600 equal regions, where EPSILON = 10^(−6) Problem is that function does...

I'm trying to convert a double to an NSDeciamlNumber. Here is my code: - (NSDecimalNumber *)myMethod { double amount = 42; ... return [NSDecimalNumber numberWithDouble:amount]; // Get warning here } But I get the following warning: Incompatible pointer types returning 'NSNumber *' from a function with result type 'NSDecimalNumber *'...

I need to convert a float representing hours to Hours:Minutes:Seconds. How is that possible by using C#. Currently i am converting this 5.4898391027272906 float hour to Hours minutes and seconds, i got a desire results for only till hours and minutes but not for seconds. Below is my code: double...

I'm trying to create a double by appending the binary representations of two ints. This is what I have now: int i = arc4random(); *(&i+1) = arc4random(); double d = *(double*)&i; I hoped the double pointer would also use the value in the &i+1 address, and this is indeed the...

I'm trying to convert a String into double. The source string is in the format "88.6" and the double I expect should be "88.60". I tried converting using Double.parseDouble, Double constructor, Double.valueOf, DecimalFormat and NumberFormat hardcoding Locale.US or Locale.ENGLISH but I still get "88,600000". How should I convert it? Thanks...

dataBuf[1] = acos(0.130f); This is the code I'm running but when I print out the result, it comes out as 1 instead of 82. dataBuf is an int16_t array. All the other math.h functions work fine with the conversion but the trig ones don't work....

This question already has an answer here: How to nicely format floating numbers to String without unnecessary decimal 0? 15 answers I would like to know how can I show in my TextView the price as follows: Price is a double value. a=8.75 and b=9.00 I need display a=8.75...

I have tried this: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *txt1; char tam[13]; char tam1[13]; char tam2[13]; txt1 = fopen("C:/Users/Hugo/Documents/C/in2.txt","r"); if(txt1 == NULL) { printf("No se puede leer el archivo"); return 0; } fgets(tam1,sizeof(tam1), txt1); double c = atof(tam1); printf("%f",c); when I debug: tam1 is...

I'm currently working with some dummy data, before I start using an actual API. But I'm having some problems filling one of my labels, with a number, that needs a symbol added to it. Rather than explaining everything, here's a screencap of an early design below: I have a double,...

This question already has an answer here: Compare two objects with .equals() and == operator 8 answers the targetPixValList is a list contains Double objects and it contains also similar values in successive position in the list, and when i tried to compare two Double values using Code_1, the...

Im working on a program for homework and so far everything prints out correctly except for the planet "Neptune". Every other choice works fine and prints out the numbers as they are supposed to be but Neptune prints out the right numbers but as negatives. I have been told to...

I'm a designer looking into learning Swift and I'm a beginner. I have no experience whatsoever. I'm trying to create a tip calculator using basic code in Xcode's playground. Here is what I have so far. var billBeforeTax = 100 var taxPercentage = 0.12 var tax = billBeforeTax * taxPercentage...

I've faced a weird case with a double variable after adding some values to it. The problem occurs when adding (0.2) to a double variable more than one time -I think it only happens with (0.2)- for example: consider this code: Dim i As Double = 2 i = i...

The question is : x and y are two floating point numbers in 32-bit IEEE floating-point format (8-bit exponent with bias 127) whose binary representation is as follows: x: 1 10000001 00010100000000000000000 y: 0 10000010 00100001000000000000000 Compute their product z = x y and give the result in binary IEEE...

Here's the class in which I try to draw the lines package gps; import java.awt.*; import java.awt.geom.Line2D; import java.util.*; import javax.swing.*; public class RoadMap extends JPanel { public void paintComponent(Graphics2D g) { super.paintComponent(g); g.setColor(Color.blue); for(int i = 0; i < Graph.getEdges().length; i++) { Shape s = new Line2D.Double(Graph.vMap.get(Graph.getEdges()[i].i1).x, Graph.vMap.get(Graph.getEdges()[i].i1).y, Graph.vMap.get(Graph.getEdges()[i].i2).x,...

I have a method that is converting a decimal (double value) into a fraction and putting the numerator and denominator values into an int[] of size 2. Testing it works out fine for most values except when I hit 0.0001. Then the return value is 1.0/1.0. The method: private static...

This question already has an answer here: Arduino: printf/fprintf prints question mark instead of float 3 answers I am completely lost on what to do with this issue. I'm not very familar with c language, but I know enough to program my Atmel MCU for a controls project. I'm...

I am attempting to use mmap to create/access twi different (N+2)*(N+2) 2D array of doubles, so that multiple threads can look at their own portion of it and change it, applying the changes so that all others can see. Here is what I have: int main(int argc, char *argv[]) {...

I have a method that is going through a CSV file and uploading to Postgres. CSV.foreach(path, converters: :all) When it encounters a number such as "2.02E+17" it is uploading "2.0150519e+17", but when it encounters "20150515E000590" it is uploading "Infinity". If I set CSV.foreach(path) When it encounters "2.02E+17" it is uploading...

How can I generate a random double in Java? All tutorials only show how to generate in a certain range, but I want all doubles possible. Is there something which just shuffles all bits and gives me the number?...

In Jaspersoft Studio I have tried the following expression. I am getting null but I don't understand why. This should be as simple as 3.00/2 and display 1.50 however it is not working it still shows null. I have confirmed that the fields contain values for all fields. The expression...

Accourding to Wikipedia the binary32 format has from 6 to 9 significant decimal digits precision and 64 format has from 15 to 17. I found that these significant decimal digits have been calculated using the Mantissa but i didn't get it how can one calculate it? Any Idea ? Mantissa...

I have a program that calculates the correlation value between a currency and a stock value. I'm adding the "pairs" (currency name + ": " + Correlation Value) in to an ArrayList and if i print out the arraylist this is my output: SDG: 0.6672481089755959 RON: 0.7950474904606127 MKD: 0.788195252851783 MXN:...

In my example I have a string: "POINT (6.5976512883340064 53.011505757047068)" What I would like is to extract the two doubles from that string and place them in separate strings. I could use a StringReader, however the doubles are not fixed in length (aka the length may vary) so I can't...

I've a condition if the a column in database has either "" or DBNull it should take it as 0. Can I have that in one line. Anyway I did that coding in the long way. Is there any possible shorter way to achieve this. This is my code: public...

It is necessary to change the type of a table field (with data). From Float type to Double type. The code that does this: ALTER TABLE `my_table` CHANGE COLUMN `my_value` `my_value` DOUBLE NULL DEFAULT NULL AFTER `id`; But I got a problem: All fractional numbers soured: Old value -> New...

Why does this code give a completely wrong answer if I use float or double but not int? //C How to Program Exercises 2.33 #include <stdio.h> #include <conio.h> double dailyDrivingCost(double miles, double costPerGallon,double averageMilesPerGallon); int main(void){ double a,b,c,d,e; printf ("Please enter the number of miles daily\n"); scanf("%lf",&a); printf ("Please enter...

I'm trying to convert a string to a double, so I can use the double to compare it with another one, to make the result green if it's the same or red when not. The first method is: public void getCords(View view) { double latitude; double longitude; latitude = 1.00;...

I got a vector of type double let's say vec. When I perform for instance test=vec.^ 1.4623; I end up with test as complex double type, and I am wondering if there is a way to convert test to double since I'd like to get decimal values. ps: It's worth...

I know how much what i'm asking about so easy, but i don't know how to search about my problem here because my question is so weird !! I do something like calculator using double, float function, and this is my code : float rn7mabv,resultbsa; double result; result=rn7mabv *resultbsa/1.73; DecimalFormat...

I came across some old legacy code as the below: s1 = Double.toString(dbVal1); s2 = Double.toString(dbVal2); if (s1.compareTo(s2)!=0) { return false; } return true; where dbVal1 and dbVal2 are both double values. I found this while profiling, and the toString method calls take a fair amount of CPU time. Is...

I have a numeric array which i wish to combine with a text array. TX = {'a' 'b' 'c'} NM = magic(30) combined = ([TX NM]) How can i manage to get the following new structure out of it: COMBI = a b c are in columns 1,2,3 and have...

I'm moving from swing to javafx. I wondered why GraphicsContext uses methods with double params. For example fillRect(double x, double y, double w, double h) unlike swing has methods drawRect(int x, int y, int width, int height). Should I do all my calculations in double?...

Could anyone help me understand why the "text" variable is empty for the below snippet, double d = 0; var text = d.ToString("##,###,###,###"); If I change the value of d to any non-zero value, I get its correct string representation....

I need a method that will accept String number as a parameter and return double if it has a remainder, or int if it is decimal. I wrote such code: private double convertToNumber(String number) { double d = Double.parseDouble(number); if (d % 1.0 == 0) { return Integer.parseInt(number); } else...

I am new to Java and did not exactly know how to search for this. Because googling for 1. double java does not give me any pleasing search results. I came across this code: public Vector normalize() { final double inorm = 1. / this.norm(); return smult(inorm); } One might...

I am getting an error message on my code to find the total salary of employee's who are payed $200 + the commission amount. Once all the employee's gross sales are input it is supposed to print out the amount of employee's that fell into each different pay category. Here...