So I have the following number
3.454545E5
Notice the "E" letter which indicates to the power of
Is there a way to conver this number to
3454545
?
double d = 3.454545E5;
int i = (int) d;
Output: 345454.
If you want exactly 3454545:
int i = (int) (d*10);
You can use DecimalFormat to format the number any way you want.
If it is a string, first parse it as a double.
double yourNumber = 3.454545E5;
String output = String.format("%d", yourNumber);
尝试这个
long l = (long) 3.454545E5;
Can you try doing this?
double num = 3.454545E5;
int num1 = (int)num;
System.out.println(num1);
Here is the result - 345454
Not sure if I understand you correctly but looks like you're interested in extracting mantissa from the number and dropping the exponent
This should work for you:
double number = 3.454545E5;
int exponent = (int)Math.log10(Math.abs(number)); // exponent = 5
double mantissa = number / Math.pow(10, exponent); // mantisa = 3.454545
To get your number you can multiply mantissa, in your particular example:
int result = (int)(mantissa * 1000000)
//result = 3454545
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.