• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert exponential to number  RSS feed

 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

I need to convert exponential to number.

How to convert it.

below is my value:

String ss = "1.2042013380240002e+25";

Orignal value of above String is 0000000000012042013380240002100389390

Need to convert from ss to number



Thanks.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forget about java, computers, programming, etc.

how would YOU convert ""1.2042013380240002e+25" into a number?
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have passed this value 0000000000012042013380240002100389390 from javascript to java.

in Javascript it is passing 1.2042013380240002e+25 value to java.

thats why i need to convert back to orignal value.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinoth sathiya wrote:I have passed this value 0000000000012042013380240002100389390 from javascript to java.
in Javascript it is passing 1.2042013380240002e+25 value to java.

I have no idea what that means.

Forget javascript. Do you want to convert the string:
"0000000000012042013380240002100389390"
or
"1.2042013380240002e+25"
?

And do you want to convert it to a number; ie, a double, or a float, or a BigDecimal, or do you want to convert it to another string?

Winston
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to convert from

1.2042013380240002e+25

to

0000000000012042013380240002100389390

either in javascript or java
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinoth sathiya wrote:I need to convert from
1.2042013380240002e+25
to
0000000000012042013380240002100389390
either in javascript or java

OK, so how do you know how long that output string is supposed to be, because it's a LOT longer than 26 digits.

Winston
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a value.

This is file name . I need to capture this file name and process it.

all are numbers only.

so that i have to put ends with .jpg. and process
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinoth sathiya wrote:This is not a value.
This is file name . I need to capture this file name and process it.

Irrelevant.

You said you want to convert "1.2042013380240002e+25" to "0000000000012042013380240002100389390".

And my question was - and still is - How do you know how long that output string needs to be?

Because it is certainly NOT 26 digits, which is what you would expect from a scientific form number with 'E+25' in it.

Winston
 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so now I am totally confused on what you are trying to do.

Again...forget about java, javascript, strings, Ints, etc. Forget about computers.

Tell us, in English, what you are trying to do. Don't tell us what is happening. Don't tell us what you need to do to fix it. Tell us what is happening.

I think this is what you are saying...

You have a file name in javascript. You need to pass this file name to java. You need help doing this.

is that correct?
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'll tell you clearly...

This is file of file "0000000000012042013380240002100389390.jpg"

i'll pass this file name to another javascript function as parameter.

e.g function sendFileName(fileName)
{------}

when i get this fileName variable. iam getting this(1.2042013380240002e+25) exponential format instead of 0000000000012042013380240002100389390.

How to get original format.

Note: fileName is always number only...



That i need to know.

 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you should be trying to convert "1.2042013380240002e+25" to "0000000000012042013380240002100389390". Your solving the wrong problem.

the correct problem to solve is "What is converting 0000000000012042013380240002100389390.jpg into 1.2042013380240002e+25?"

if 0000000000012042013380240002100389390.jpg is the file name, you should be passing the filename, not converting it to an int and then back to a string.
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm not converting from 0000000000012042013380240002100389390 to 1.2042013380240002e+25.


am passing fileName only.

when i get from javascript function value means it is showing 1.2042013380240002e+25(exponential notation).

why javascript is implicitly formatting with exponential form when i pass 0000000000012042013380240002100389390 ?

Iam passing 0000000000012042013380240002100389390 this only. but getting 1.2042013380240002e+25 from javascript function.


Passed : 0000000000012042013380240002100389390

got : 1.2042013380240002e+25.

I need passed value only.





 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well..You do realize that you are on a JAVA forum. Asking JavaScript questions here may not get you help quite as quickly as you want it.

Next...1.2042013380240002e+25 IS the value of 0000000000012042013380240002100389390 - or is as close to the value as most programming languages can represent.

The value of:
seven
7
VII
4 + 3

are all the same, regardless of how you write it.

I have no idea if javascript, like perl, treats variables contextually, and converts from a string to a numeric as needed or not, but it is possible. How you get around that, I don't know.

You may also want to post your ACTUAL code so we can see what you are really doing. If it is javascript, I won't have a clue, but someone else around here might.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vinoth sathiya wrote:
Passed : 0000000000012042013380240002100389390

got : 1.2042013380240002e+25.

I need passed value only.


The problem with this conversion is that it is lossy. Data is lost during the conversion, hence, it can't be converted back correctly. The data just isn't available. The best that you can do is 12042013380240002000000000 when you convert it back. Notice that all the leading zeros are gone (as you don't know how many are there), and the trailing numbers are gone too (replaced with zeros). Also, the last non-zero number, in this case "2", may be incorrect, as the conversion to scientific notation may have rounded it off.

One possible option is to convert it to a regex instead. The trailing zeros and last digit is any character. There is a regex component for leading zeros. And the regex is used in a FilenameFilter. etc. So, you can look for a file with the filename that matches the regex "0*1204201338024000..........\.jpg". Of course, the bad news here is that it is likely that it will match more than one file -- particularly for the trailing numbers.

Henry
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:
I have no idea if javascript, like perl, treats variables contextually, and converts from a string to a numeric as needed or not, but it is possible. How you get around that, I don't know.


yeah, Javascript does do automatic type conversion. The fact that it started as a filename meant it probably started off as a string. The OP should revisit the js code, to try to prevent the conversion from happening -- which can be done with a combination of initializing interim variables to string, and casting to prevent the conversion.

Henry
 
vinoth sathiya
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for reply.....

There is a fixed zero's of 11 digits.

other than zero i need to get it correctly..

my question is, Is there any possible to control parameter value as string,number ? like java?

and i tested my code. with append 'G' with 0000000000012042013380240002100389390G

it is not getting the value...

e.g function sendFileName(fileName)
{
alert(fileName);

}

nothing getting anything in alert....



 
fred rosenberger
lowercase baba
Bartender
Posts: 12562
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:... post your ACTUAL code so we can see what you are really doing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!