FAQ Database Discussion Community


Large number of operations on double data type producing zero as result

java,floating-point,double
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++)...

Reading FORTRAN-written double precision variables in R

r,fortran,double
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?

“(int)Math.ceil(double)” always return 1 when values is greater than 0

java,casting,int,double,rounding
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,...

PHP function to determine if a variable is a number(not hex or other numericals that have letters in them)

php,double,numeric
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.

printing a double variable with %f and the terminal is displaying a “?” [duplicate]

c,printf,double
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...

Convert MATLAB type: from complex double to double

arrays,matlab,vector,double,complex-numbers
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...

Issue with reading and storing data from .txt file into array

java,arrays,string,loops,double
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...

Shorten double value x digit

c,double,floor
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...

Screen flickers when setting background

java,swing,double,buffer,flicker
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...

Sorting an array of Strings with a numeric value, java

java,string,sorting,arraylist,double
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:...

Double error message with remote data annotation mvc 5

asp.net-mvc,double,data-annotations
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...

Java issue converting String to double

java,double
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...

Datagridview valuetype property not changing

vb.net,datagridview,double,value-type
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...

how can we have double digit range drop downs in rails forms? that gerates drop down with numbers like 00,01, 02 etc, instead 0,1 , 2 etc?

ruby-on-rails,double,range,digit
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.,

PostgreSQL - get all integer digits from double precision field for use in to_char function

postgresql,double,precision,numeric,to-char
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,...

Why GraphicsContext uses methods with double params?

java,swing,javafx,int,double
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?...

how to create a result of double number with zero?

java,android,double
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...

C#, selecting certain parts from string

c#,string,select,double,stringreader
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...

PHP preg_match double quote matching

php,regex,double,double-quotes
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...

Convert a string to a double for a if clause

android,string,if-statement,double
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;...

Java: I want to get an Integer output in double datatype

java,double,decimal
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...

Calculating floating points as binary

double,bit-manipulation,point,floating
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...

Convert char array into double [closed]

c,printf,double,fgets,atof
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...

Trying to draw lines based on doubles but nothing shows?

java,swing,jpanel,double,graphics2d
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,...

Using int, double and long in calculation of powers

java,int,double,long-integer
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...

String to double with decimal

string,matlab,double
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...

Error when type float, no error when type double

java,floating-point,double
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...

why “==” operator does not work [duplicate]

java,list,arraylist,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...

Why does program provide -143155…when I only switched from int to double? [closed]

c,int,double
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...

scanf issue when reading double

c,gcc,double,user-input,scanf
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...

Why one of the two values (they seem to be a Strings) is converted to Double, and the second one is not while parsing from JSON in Swift?

json,swift,parsing,double
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...

Illegal conversion exception?

java,arrays,int,double,counter
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...

C++ - How to correctly cast double to int

c++,casting,int,double,precision
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....

App Crashes With editText

java,android,if-statement,android-activity,double
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...

Check if two numbers exist in two dependent arrays - Java

java,arrays,double
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...

VB.Net Double comparison after some additions

vb.net,comparison,double
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...

Wrong output from an double operation

java,double,arithmetic-expressions
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...

double to int conversion not working using math.h functions in c

c,int,double,type-conversion,math.h
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....

precision of comparing double values with EPSILON in C

c,floating-point,double,epsilon
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...

Double not parsing correctly when high enough

c#,double,exponential
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...

Will nullable value consider both null (“”) and DBNull at the same time

c#,asp.net,double,nullable,dbnull
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...

large numbers and float and double in C

c,matrix,floating-point,double,gpu
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...

Given a microsecond value , how to accurately get a timeval struct? /*UPDATE GETTING NEGATIVE VALUE*/

c++,timestamp,double,rounding
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...

mysql convert float to double

mysql,double,alter-table
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...

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

java,double
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...

JUnit's assertEquals denies assertTrue [duplicate]

java,junit,double,point
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 =...

How do I convert a double into an n-character string using exponential notation?

java,string,formatting,double
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...

How to display multiple leading zeros for floating point values in C++? [duplicate]

c++,stream,printf,double,stringstream
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...

Understanding DBL_MAX

c,floating-point,double,double-precision
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",...

defining decimal places of a double number in Java

java,double
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?...

Create double by appending binary representations of two ints

c,binary,double,bit-manipulation,arc4random
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...

Swift Downcasting AnyObject (Float) to String

ios,string,swift,double,downcasting
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,...

Adding zeros in front of double

java,double
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...

Normalization in Java (dataset of doubles)

java,double,cluster-computing,normalization
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...

Converting decimal to fraction

java,split,double,decimal,fractions
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...

HashCode calculation from double

java,double,override,long-integer,hashcode
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...

How to parse “1,234.56” in Java as Double?

java,double,locale
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");...

Double.ToString returns empty for 0

c#,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....

How to round a double to the nearest 10th place [duplicate]

java,double,number-rounding
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...

Cast double to unsigned long C++

c++,casting,double,long-integer,unsigned
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...

Validate double number in current culture

c#,parsing,double,cultureinfo,currentculture
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...

the usage of the long double

c,casting,double,long-integer
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...

Matlab string to double (str2double)

matlab,casting,double
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...

Why is dividing double values returning null?

java,null,double,divide
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...

multiple arguments in a printf method

java,printf,double
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...

Function to convert double to string with given options

c#,string,double,decimal
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)...

Java double comparing vs. String comparing

java,compare,double
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...

significant decimal digits of binary32 and binary64

floating-point,double,ieee-754,floating-point-conversion,significant-digits
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...

1. / this.norm(); Is `1.` just syntactic sugar?

java,double
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...

Multiplying variables and doubles in swift

swift,variables,double,multiplying
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...

float representing hours to hours:minutes:seconds using c#

c#,double,timespan
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...

Java generate random double

java,random,double
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?...

Validator in composite throws ClassCastException when using java.lang.Double value

validation,jsf,double,classcastexception,composite-component
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,...

Convert String Type to Double without Double.parseDouble()

java,string,nullpointerexception,type-conversion,double
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...

Difference between malloc() and simple declaration in fixed sizes [duplicate]

c,double,malloc,difference
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...

Java method returns double | int

java,int,double,primitive
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...

Can std::uniform_real_distribution(0,1) return a value greater than 0.99999999999999994?

c++,c++11,random,double,double-precision
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 =...

>= not working, R [duplicate]

r,if-statement,double,logic
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...

Show price - double as Integer depending on its value in TextView - Android [duplicate]

android,textview,integer,double
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...

BoundField double show as many decimal places as needed

asp.net,gridview,double,dataformat,boundfield
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...

Type mismatch: cannot convert from boolean to double

java,double
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...

Get warning when convert double to NSDecimalNumber

ios,objective-c,methods,double,nsdecimalnumber
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 *'...

Find out if you're reading int or double using fscanf

c,parsing,int,double,fscanf
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...

MIPS float printing

double,mips
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...

Calculating time for any sum to double, at a given rate of interest compounded annually

c++,while-loop,int,double
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...

Different results on CPU and GPU

c++,cuda,double,gpu,nvidia
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...

C# losing precision thus making equation result 0

c#,double,precision
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?...

Value of variable as integer and as double

c++,c,integer,double
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...

Add data fromEeditText to double

android,double
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...

Why Implicit Cast from double to float available?

c++,double,turboc++
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...

How do I call the first area method from the main method?

java,math,double,overloading,area
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...

Using float and double for calculation, giving different results [duplicate]

java,floating-point,double
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...

Table model cannot converted to String

java,double,tablemodel
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());...

Change decimal numbers in variable editor in MATLAB

matlab,double,decimal
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...

Integer to Double variable

java,arrays,variables,integer,double
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......

How to combine numeric and text in an array smartly

arrays,matlab,matrix,double,cell
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...

Can't seem to get .doubleValue() to work (I have the latest version of Java)

java,double
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...

Ruby CSV gem returning Infinity instead of double

ruby,postgresql,csv,double,infinity
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...

Using mmap to allocate double 2D array

c,arrays,double,mmap
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[]) {...

Convert DoubleBinding value to IntegerBinding

binding,javafx,double,javafx-8
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...