Hexagon Geospatial
MENU

ERDAS IMAGINE

Discuss and share topics of interest using ERDAS IMAGINE the world’s leading geospatial data authoring system.
Showing results for 
Search instead for 
Do you mean 
Reply
Frequent Contributor
Posts: 106
Registered: ‎06-03-2016
Accepted Solution

HOWTO: Convert a number in scientific notation to a decimal

For whatever reason I was having trouble using very small decimals (given in scientific notation) with the FilterByAttribute operator and thought rendering my value as a proper decimal might solve that and be easy enough to do. Turns out that (1) it was as easy as drawing a straight line (with my feet using only bezier curves) and (2) FilterByAttribute supports scientific notation so none of this was necessary, but I thought I'd share anyway since the picture widget is working.

 

So this sub-model takes a float in scientific notation and renders it as a string in decimal form. 

 

ex sci2str.png

 

 

The model essentially does a bunch of string processing. I remove the decimal and split the string at the exponent, write that piece out to a temp file (since it was impossible to cast text split from a string like "15" as any kind of number), read it back from the file as the Integer N, grab the first N zeros from a string of zeros, prefix that with a "0." and suffix it with the numerical part of the split string... ... ...

 

 

float2decimal.png

 

 

Wasn't a bad toy problem and I'm sure there's an easier approach.

 

Highlighted
Staff
Posts: 121
Registered: ‎07-04-2016

Re: HOWTO: Convert a number in scientific notation to a decimal

[ Edited ]

Hello Noel,

 

Nice model. Thank you for sharing your solution. Just it would not work if you will specify the number different from e-15.

 

I have some additional solution for you through simple Python script:

 

2016-09-26 13_15_05-Untitled_1 - ERDAS IMAGINE 2016.png

 

It displays up to 20 decimal places, tailing zeros are removed.

 

And then you can convert the number to string if you need. But I believe that idea is to get just decimal.

 

2016-09-26 13_31_48-Untitled_1 - ERDAS IMAGINE 2016.png

 

You can find model as well as *.py file in attachment.

 

P.S. It has it's own limitation as well. Numbers provided in scientific notation are converted to a floating-point binary representation and it is not possible to revert this process without losing information. The problem is floating point representation of real numbers on a computer uses base 2, not 10 and real numbers are approximated to the closest representation in binary system. There are additional limits connected with mantissa limits that holds significant digits of a floating point number.

 

But still it gives you some variation of possible inputs. And you always can modify the number of decimal places by changing the number (in red circle below):

 

2016-09-26 14_03_06-Document1 - Word.png

 

Kind Regards,

Marina Vardovska

Post-Sales Engineer Remote Sensing

Hexagon Geospatial Division

 

 

 

 

 

 

Kind Regards,
Marina Vardovska
Hexagon Geospatial Support
Frequent Contributor
Posts: 106
Registered: ‎06-03-2016

Re: HOWTO: Convert a number in scientific notation to a decimal


Good grief. All that effort and it doesn't work! That's just too funny!

Thanks for shining a light on the Python operator.

I tend to steer clear of the operators I can't use online, but appreciate your effort, the lengthy explanation, and the humor.

Cheers

Staff
Posts: 121
Registered: ‎07-04-2016

Re: HOWTO: Convert a number in scientific notation to a decimal

Dear Noel,

 

My apologies. At some point to make it work with other number, I was need to re-run TableFileInput operator.

Sorry, my mistake. You have perfect solution for online usage. 

 

Kind Regards,

Marina

Kind Regards,
Marina Vardovska
Hexagon Geospatial Support
Frequent Contributor
Posts: 106
Registered: ‎06-03-2016

Re: HOWTO: Convert a number in scientific notation to a decimal

Oh, no need to apologize. I started my day with a good laugh; thank you very much.

I knew there had to be a better way - there often is - and there it is.

Regards
Do you need immediate support?
If you encounter a critical issue and need immediate assistance please submit a Service Request through our Support Portal.