double

how to retrieve a Double value from one activity to another?

匆匆过客 提交于 2019-12-07 12:32:29
问题 I have made an application containing 2 activities ,in that first activity contains some EditTexts (decimal numbers),and anothe ractivity also contains some Edtitexts(decimal) ,now I want to pass one EditText's value to another but as a "double" not as a string.Because that values will be used in mathematical calculation. I want that values in "double" strictly. I have tried as below: but have no idea how to cast a String to "double". activity1.java final Double d1; final Double d2; final

Convert double to scientific notation with specific number after decimal points

╄→гoц情女王★ 提交于 2019-12-07 12:23:35
问题 I want to convert double to scientific notation like this: -0.00752382528 => -.752383E-1 can i do this with .ToString() or Regex? 回答1: You can either use the standard format string for scientific notation: (-0.00752382528).ToString("E5") // returns "-7.52383E-003" or if you don't want the leading zeros in the exponent, use a custom string: (-0.00752382528).ToString("0.00000E0") // returns "-7.52383E-3" 来源: https://stackoverflow.com/questions/25851179/convert-double-to-scientific-notation-with

How to check if a string can be converted to double in C++?

孤人 提交于 2019-12-07 12:16:15
问题 I have a string which can be a number (even a float or double type, not only integer), and it can be also a word which is non-numeric. I would like to check if this string can be converted into double, and if so, then I would like to do the conversion. In case of a non-numeric string, I want different behaviour. I have tried this: double tmp; string str; stringstream ss; ss << str; ss >> tmp; if (ss.fail()) { // non-numeric string } else { // string to double conversion is successful } The

NumberFormatException on European Versions of Android?

删除回忆录丶 提交于 2019-12-07 11:58:44
问题 I have an app which runs the following two lines of code upon starting: DecimalFormat decim = new DecimalFormat("#.00"); return Double.parseDouble(decim.format(totalNumberOfCredits)); When I start the app on my American phone, the value of decim.format(totalNumberOfCredits) is .00 . However, in my Google Play Developer Console, I have a dozen crashes, all of which look like this: Caused by: java.lang.NumberFormatException: Invalid double: ",00" at java.lang.StringToReal.invalidReal

Problem on getting digits in a double variable

巧了我就是萌 提交于 2019-12-07 08:23:53
问题 I got a little problem with a function I need in my java progam. I want to check the total amount of digits, a 'double' variable has. (e.g.: 5 should return 1, 5.0034 should return 5, and 2.04 should return 3.) My function is this: private int getDoubleLength (double a) { int len = 0; while (a != (int) a) { a *= 10; } while (a > 1) { len ++; a/=10; } System.out.println(String.format("Double %f has %d digits.",a,len)); return len; } Now this works perfectly, but when I am making some

How do I read input that could be an int or a double? [duplicate]

纵饮孤独 提交于 2019-12-07 06:44:46
问题 This question already has answers here : How to test if a double is an integer (14 answers) Closed 4 years ago . I'm writing a program in which I need to take input from the keyboard. I need to take a number in, yet I'm not sure if it's an int or a double . Here's the code that I have (for that specific part): import java.io.*; import java.util.*; //... Scanner input = new Scanner(System.in); int choice = input.nextInt(); I know I can get a String and do parseInt() or parseDouble() , but I

Underlining Text in an <input> Box

心已入冬 提交于 2019-12-07 06:41:14
问题 I've gotten a request from a client to underline text in a text field. Both single and double lines. Is this even possible? I assume with some obscure plugin but I haven't found it yet. :P I've thought about there being 2 possibilities, if this is possible. Underlining the text in the actual field. Doing some crazy hack with text just underneath the text field. Thanks for any help and/or commentary. ^_^ 回答1: The following works in Chrome 6.0.472.55/Ubuntu 10.04, and Firefox 3.6.9 (also Ubuntu

Reusing a data dictionary for 'Deflate' separate from the compressed data

匆匆过客 提交于 2019-12-07 05:56:19
问题 I am storing many chunks of base64 encoded 64-bit doubles in an XML file. The double data all looks similar. The double data is currently being compressed using the java 'Deflate' algorithm before the encoding, however each chunk of binary data in the file will have its own deflate data dictionary, which is an overhead I would like to greatly lessen. The 'Deflater' class has a 'setDictionary' method which I would like to use. So questions are: 1). Does anyone have any suggestions for how to

How deal with the fact that most decimal fractions cannot be accurately represented in binary?

泄露秘密 提交于 2019-12-07 04:48:39
问题 So, we know that fractions such as 0.1, cannot be accurately represented in binary base, which cause precise problems (such as mentioned here: Formatting doubles for output in C#). And we know we have the decimal type for a decimal representation of numbers... but the problem is, a lot of Math methods, do not supporting decimal type, so we have convert them to double, which ruins the number again. so what should we do? 回答1: For a comprehensive examination of the challenges involved in

Can we use double to store monetary fields and use BigDecimal for arithmetic

痞子三分冷 提交于 2019-12-07 04:44:28
问题 I know the problem with double/float, and it's recommended to use BigDecimal instead of double/float to represent monetary fields. But double/float is more effective and space-saving. Then my question is: It's acceptable to use double/float to represent monetary fields in Java class, but use BigDecimal to take care of the arithmetic (i.e. convert double/float to BigDecimal before any arithmetic) and equal-checking? The reason is to save some space. And I really see lots of projects are using