double

Any equivalent of “extended” for C#?

安稳与你 提交于 2020-01-03 08:39:23
问题 I'm working on a new version of my Mandelbrot screensaver and I'm running out of floating point accuracy - simple double values don't have enough significant figures for my needs. More significant figures = greater levels of zooming into the fractal Back when I wrote a version of this screensaver in Delphi 7, I used the extended floating point type, 80 bits in size. In .NET, I could switch to decimal, but the performance hit for this is terrible, slowing down fractal generation by a factor of

Addition of very small Double values (Java) [duplicate]

不打扰是莪最后的温柔 提交于 2020-01-03 05:06:04
问题 This question already has answers here : How many significant digits do floats and doubles have in java? (6 answers) Closed 2 years ago . I was wondering, why my simple addition of some double values leads to the following results in Java: double a = 1 + 1E-10; // 1.0000000001 (as expected) double b = 1 + 1E-15; // 1.000000000000001 (as expected) double c = 1 + 1E-20; // 1.0 (why?) I thought I can at least add a value of Double.MIN_VALUE, which seems to be 4.9E-324. What am I doing wrong here

Addition of very small Double values (Java) [duplicate]

*爱你&永不变心* 提交于 2020-01-03 05:06:01
问题 This question already has answers here : How many significant digits do floats and doubles have in java? (6 answers) Closed 2 years ago . I was wondering, why my simple addition of some double values leads to the following results in Java: double a = 1 + 1E-10; // 1.0000000001 (as expected) double b = 1 + 1E-15; // 1.000000000000001 (as expected) double c = 1 + 1E-20; // 1.0 (why?) I thought I can at least add a value of Double.MIN_VALUE, which seems to be 4.9E-324. What am I doing wrong here

Only show decimal portion of Double with the decimal point

天涯浪子 提交于 2020-01-02 22:07:41
问题 I'm trying to only show the decimal portion of a number but it keeps printing the number with the decimal point: for number 223.50: changeAmountLabel.text = "\(balance.truncatingRemainder(dividingBy: 1))" this will print .5, but what needs to be printed is 50, is there a way to do this? 回答1: You can do this by using a NumberFormatter . Try this: let formatter = NumberFormatter() formatter.locale = Locale(identifier: "en_US_POSIX") formatter.minimumFractionDigits = 2 formatter

objective-c stringvalue from double

早过忘川 提交于 2020-01-02 02:55:09
问题 I have the following code: double d1 = 12.123456789012345; NSString *test1 = [NSString stringWithFormat:@"%f", d1]; // string is: 12.123457 NSString *test1 = [NSString stringWithFormat:@"%g", d1]; // string is: 12.1235 How do I get a string value that is exactly the same as d1? 回答1: It may help you to take a look at Apple's guide to String Format Specifiers. %f 64-bit floating-point number %g 64-bit floating-point number (double), printed in the style of %e if the exponent is less than –4 or

How to remove trailing zero in a String value and remove decimal point [duplicate]

北城余情 提交于 2020-01-02 01:38:28
问题 This question already has answers here : How to nicely format floating numbers to String without unnecessary decimal 0? (25 answers) Closed 5 years ago . How do I remove trailing zeros in a String value and remove decimal point if the string contains only zeros after the decimal point? I'm using the below code: String string1 = Double.valueOf(a).toString() This removes trailing zeros in (10.10 and 10.2270), but I do not get my expected result for 1st and 2nd inputs. Input 10.0 10.00 10.10 10

C# Casting to a decimal

瘦欲@ 提交于 2020-01-02 01:06:10
问题 What, if any, is the difference between? decimal d = (decimal) myDouble; decimal d = new decimal(myDouble); decimal d = Convert.ToDecimal(myDouble); 回答1: There is no difference. If you look at the source: In Decimal: public static explicit operator decimal(double value) { return new decimal(value); } In Convert: public static decimal ToDecimal(float value) { return (decimal) value; } So in the end they all call new decimal(double) . 回答2: They all achieve the same results. However, here's a

Swift - Convert values in array to doubles or floats

故事扮演 提交于 2020-01-01 18:57:43
问题 I have an array with values which are strings (but all the strings are values like 1.0, 2.0, etc). I'm trying to convert those strings into doubles or floats so I can add them all together. How do I do this in swift? 回答1: update: Xcode 8.3.2 • Swift 3.1 extension Collection where Iterator.Element == String { var doubleArray: [Double] { return flatMap{ Double($0) } } var floatArray: [Float] { return flatMap{ Float($0) } } } usage: let strNumbersArray = ["1.5","2.3","3.7","4.5"] // ["1.5", "2.3

Converting big decimal to double without exponential format

让人想犯罪 __ 提交于 2020-01-01 18:54:20
问题 I'm doing calculations on High decimal precision BigDecimal objects. I'm using a third party library that requires the parameter in double. When I try to convert this to double i get the values in exponential format instead of decimals . BigDecimal 0.000035000000000 Double 3.5E-5 BigDecimal bd; BigDecimal(0.0000349999999995631583260546904057264328002929687500); bd= bd.setScale(15,BigDecimal.ROUND_CEILING); Log.i("bd","bd "+bd.toPlainString()); Log.i("bd","double"+bd.doubleValue()); I have

Rounding double values in C++ like MS Excel does it

拈花ヽ惹草 提交于 2020-01-01 15:33:51
问题 I've searched all over the net, but I could not find a solution to my problem. I simply want a function that rounds double values like MS Excel does. Here is my code: #include <iostream> #include "math.h" using namespace std; double Round(double value, int precision) { return floor(((value * pow(10.0, precision)) + 0.5)) / pow(10.0, precision); } int main(int argc, char *argv[]) { /* The way MS Excel does it: 1.27815 1.27840 -> 1.27828 1.27813 1.27840 -> 1.27827 1.27819 1.27843 -> 1.27831 1