Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4267686
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:56:00+00:00 2026-05-21T06:56:00+00:00

parseFloat(1.51e-6); // returns 0.00000151 parseFloat(1.23e-7); // returns 1.23e-7 // required 0.000000123 I am sorting

  • 0
parseFloat(1.51e-6);
// returns 0.00000151

parseFloat(1.23e-7);
// returns 1.23e-7
// required 0.000000123

I am sorting table columns containing a wide range of floating-point numbers, some represented in scientific notation.

I am using the jQuery tablesorter2.0 plugin which is using ‘parseFloat’ for cells that start with a digit.
The issue is that parseFloat returns very small numbers represented as 1.23e-7 as a string and is not expanding this to 0.000000123.
As a result tablesorter sorts the content of the column as text instead of numerics.

**Column To Sort**
2.34
1.01
13.56
1.23e-7

**After Sort Now**
1.01
1.23e-7
13.56
2.34

**Expect**
1.23e-7
1.01
2.34
13.56

Is there an efficient way of representing very small scientific notation numbers as expanded floating-point numbers?

Solution:

tablesorter determines how to sort a column based on the first of tablesorters automatic parsers to return true for the content of a cell in that column.
If the cell contained 1.23e-7 than it defaulted to sort by text because the ‘digit’ parser does not interpret this as a number.

So to workaround, the following code represents the scientific notation number as a string that tablesorter can interpret/parse as a digit and so ensures numerical sorting on the column. @bitplitter – thanks for the toFixed() tip.

var s = "1.23e-7";
// Handle exponential numbers.
if (s.match(/^[-+]?[1-9]\.[0-9]+e[-]?[1-9][0-9]*$/)) {
  s = (+s).toFixed(getPrecision(s));
}
//returns 0.000000123

// Get a nice decimal place precision for the scientific notation number.
// e.g. 1.23e-7 yields 7+2 places after the decimal point
// e.g. 4.5678e-11 yields 11+4 places after the decimal point
function getPrecision(scinum) {
  var arr = new Array();
  // Get the exponent after 'e', make it absolute.  
  arr = scinum.split('e');
  var exponent = Math.abs(arr[1]);

  // Add to it the number of digits between the '.' and the 'e'
  // to give our required precision.
  var precision = new Number(exponent);
  arr = arr[0].split('.');
  precision += arr[1].length;

  return precision;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:56:01+00:00Added an answer on May 21, 2026 at 6:56 am

    Even though the OP has posted his solution, I’d like to share a rather simpler solution I stumbled upon, which is based on the parsers in the tablesorter source code and the regex given by JasonS on another question.

    // add parser through the tablesorter addParser method 
    $.tablesorter.addParser({ 
    // set a unique id
    id: 'scinot', 
    is: function(s) { 
        return /[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/.test(s); 
    }, 
    format: function(s) { 
        return $.tablesorter.formatFloat(s);
    }, 
    type: 'numeric' 
    });
    

    It works on my tables with pretty much all values given in scientific notation. It auto-detects (the is: part) and correctly sorts multiple fields.
    Hope it helps others who might stumble upon this question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

View this code: function testprecision(){ var isNotNumber = parseFloat('1.3').toPrecision(6); alert(typeof isNotNumber); //=> string }
As you know, the javascript's parseFloat function works only until it meets an invalid
I have this JavaScript function: Contrl.prototype.EvaluateStatement = function(acVal, cfVal) { var cv = parseFloat(cfVal).toFixed(2);
... float value = Float.parseFloat((String)model.getValueAt(e.getLastRow(), 1)); DecimalFormat dec = new DecimalFormat(#.###); model.setValueAt(dec.format(value), e.getLastRow(), 1);
I am sure this has more to do with my understanding of the behaviour
How is parseInt() different from valueOf() ? They appear to do exactly the same
What's your favorite way of testing javascript code snippets? I like to use the
var total = 0; $(.amount).each(function () { var value = $(this).val(); value = (value.length
I am using this code to sum values from multiple radio buttons : $(document).ready(function(){
I am using the following code to get the version of IE in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.