Java/Android scientific number to html
I'm a newbie at programming and maybe there is a solution to this problem I just don't know about. I have a TextView with values. As some of the values are really small they are shown as scientific numbers. But I don't like the 2e-02 expression I'd like to convert it to an Spannable which looks like 开发者_运维技巧2*10-2. Is there an easy (already implemented way) or do I have to do a loop to count the number of decimal places (all my numbers are << 1) to create a html string?
It is just a question out of curiosity because I'm unable to find anything about this neither in books nor online. I don't have problems actually writing the function itself.
Assuming all your numbers are formatted like that, here’s how I would do it:
scientific.replace(/(.*)e-0*(.*)/, "$1 × 10<sup>−$2</sup>")
精彩评论