double

Scanning doubles when I separate decimals with comma or dot

删除回忆录丶 提交于 2020-02-25 00:13:02
问题 I'm rather new to Java and I was making a simple calculator. Problem is when I my input number is for example "3.1" it gives an exception error, but when writing "3,1" it works just fine. My friend, however, has a slightly more advanced calculator (with string parsing) and when I run his code the opposite happens: 3,1 gives exception error, 3.1 works perfectly. I was looking forward to know what causes these different behaviors. I made this simple sum just now and the same happens, I'll edit

How can I convert string to double? [duplicate]

只谈情不闲聊 提交于 2020-02-24 14:11:05
问题 This question already has answers here : Converting String to Double in Android (8 answers) Closed 6 days ago . I am developing an android app. I need to convert string to double. How can I do it? 回答1: You just need this : double d=Double.parseDouble(myString); If your String value cannot be parsed to double it will throw NumberFormatException . So better you put the parseDouble statement inside try catch block. 回答2: here is the example try{ double dbl = Double.parseDouble("99.882039"); catch

How can I convert string to double? [duplicate]

∥☆過路亽.° 提交于 2020-02-24 14:10:30
问题 This question already has answers here : Converting String to Double in Android (8 answers) Closed 6 days ago . I am developing an android app. I need to convert string to double. How can I do it? 回答1: You just need this : double d=Double.parseDouble(myString); If your String value cannot be parsed to double it will throw NumberFormatException . So better you put the parseDouble statement inside try catch block. 回答2: here is the example try{ double dbl = Double.parseDouble("99.882039"); catch

How can I convert string to double? [duplicate]

▼魔方 西西 提交于 2020-02-24 14:08:30
问题 This question already has answers here : Converting String to Double in Android (8 answers) Closed 6 days ago . I am developing an android app. I need to convert string to double. How can I do it? 回答1: You just need this : double d=Double.parseDouble(myString); If your String value cannot be parsed to double it will throw NumberFormatException . So better you put the parseDouble statement inside try catch block. 回答2: here is the example try{ double dbl = Double.parseDouble("99.882039"); catch

How can I convert string to double? [duplicate]

☆樱花仙子☆ 提交于 2020-02-24 14:06:10
问题 This question already has answers here : Converting String to Double in Android (8 answers) Closed 6 days ago . I am developing an android app. I need to convert string to double. How can I do it? 回答1: You just need this : double d=Double.parseDouble(myString); If your String value cannot be parsed to double it will throw NumberFormatException . So better you put the parseDouble statement inside try catch block. 回答2: here is the example try{ double dbl = Double.parseDouble("99.882039"); catch

Java double initialization

女生的网名这么多〃 提交于 2020-01-30 19:37:57
问题 In what way are these statements different? double dummy = 0; double dummy = 0.0; double dummy = 0.0d; double dummy = 0.0D; 回答1: Having tried a simple program (using both 0 and 100, to show the difference between "special" constants and general ones) the Sun Java 6 compiler will output the same bytecode for both 1 and 2 (cases 3 and 4 are identical to 2 as far as the compiler is concerned). So for example: double x = 100; double y = 100.0; compiles to: 0: ldc2_w #2; //double 100.0d 3: dstore

Java double initialization

痞子三分冷 提交于 2020-01-30 19:37:05
问题 In what way are these statements different? double dummy = 0; double dummy = 0.0; double dummy = 0.0d; double dummy = 0.0D; 回答1: Having tried a simple program (using both 0 and 100, to show the difference between "special" constants and general ones) the Sun Java 6 compiler will output the same bytecode for both 1 and 2 (cases 3 and 4 are identical to 2 as far as the compiler is concerned). So for example: double x = 100; double y = 100.0; compiles to: 0: ldc2_w #2; //double 100.0d 3: dstore

Why uint64_t cannot show pow(2, 64) - 1 properly?

旧街凉风 提交于 2020-01-30 13:04:50
问题 I'm trying to understand why uint64_t type can not show pow(2,64)-1 properly. The cplusplus standard is 199711L. I checked the pow() function under C++98 standard which is double pow (double base , double exponent); float pow (float base , float exponent); long double pow (long double base, long double exponent); double pow (double base , int exponent); long double pow (long double base, int exponent); So I wrote the following snippet double max1 = (pow(2, 64) - 1); cout << max1 << endl;

Why uint64_t cannot show pow(2, 64) - 1 properly?

雨燕双飞 提交于 2020-01-30 13:04:30
问题 I'm trying to understand why uint64_t type can not show pow(2,64)-1 properly. The cplusplus standard is 199711L. I checked the pow() function under C++98 standard which is double pow (double base , double exponent); float pow (float base , float exponent); long double pow (long double base, long double exponent); double pow (double base , int exponent); long double pow (long double base, int exponent); So I wrote the following snippet double max1 = (pow(2, 64) - 1); cout << max1 << endl;

How to format floating point value with fix number of digits?

扶醉桌前 提交于 2020-01-30 13:02:47
问题 Is it possible in C# to format a double value with double.ToString in a way that I have always a fixed number of digits, no matter on which side of the decimal point? Say I wish 6 digits, I want to have these results: 0.00123456789 gives "0.00123" 1.23456789 gives "1.23457" 123.456789 gives "123.457" 0.0000000123456789 gives "0.00000" 12345678.9 gives "12345679" (on overflow I want to see all digits left of decimalpoint) 4.2 gives "4.20000" I'm experimenting with double.ToString, but cannot