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 3694932
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:33:23+00:00 2026-05-19T04:33:23+00:00

I have some floating point numbers where I would like to indicate that that

  • 0

I have some floating point numbers where I would like to indicate that that the last few digits are not that important. What I have in mind is something like this.

For the number 273.978

<span style="font-weight:bold">273.9</span><span style="color:#3399ff">78</span>

It would be great if there were something like a “nth-last-chars” CSS selector. Then I could set this all up in my CSS file, instead of chopping the number in JavaScript. Is there a better way to achieve this?

EDIT: Here’s what a native JavaScript solution looks like:

<span id="numstart" style="font-weight:bold">123.4</span><span id="numend" style="color:#3399ff">57</span>

<script>
var newnum = 273.978;
var numStr = String(newnum)
var numLen = numStr.length;
var newStart = numStr.substring(0,numLen-2);
var newEnd = numStr.substring(numLen-2,numLen);
document.getElementById("numstart").innerHTML = newStart;
document.getElementById("numend").innerHTML = newEnd;
</script>
  • 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-19T04:33:23+00:00Added an answer on May 19, 2026 at 4:33 am

    Off the top of my head in jQuery:

    <script type="text/javascript">
    $('.numbers').each(function() {
        $(this).html(
            $(this).html().substr(0, $(this).html().length-2)
              + "<span style='color: #3399ff'>"
              + $(this).html().substr(-2)
              + "</span>");
    });
    </script>
    

    Here’s a fiddle to demonstrate it. I’m sorry it’s not plain JavaScript, but I’m sure one of the folks here can offer a native solution if this doesn’t cut your corn.

    UPDATE: And here’s a non-jQuery solution, and another fiddle demonstrating it. I also broke the style out into CSS.

    <style type="text/css">
    .unimportant {
        color: #3399ff;
    }
    </style>
    
    <script type="text/javascript">
    var numberTargets = document.getElementsByClassName('number');
    for(i=0; i<numberTargets.length; i++) {
        var html = numberTargets[i].innerHTML;
        numberTargets[i].innerHTML = html.substr(0, html.length-2)
          + "<span class='unimportant'>"
          + numberTargets[i].innerHTML.substr(-2)
          + "</span>";
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some inputs on my site representing floating point numbers with up to
I recently realized that some countries display floating point numbers with different comma/period notation.
I have some UI in VB 2005 that looks great in XP Style, but
We have some input data that sometimes appears with &nbsp characters on the end.
I have some classes layed out like this class A { public virtual void
I have some code like this in a winforms app I was writing to
We have some files on our website that users of our software can download.
I would like to create a function that checks if a numeric value passed
what is the best way to handle floating point numbers in XML? If I
Some of my data are 64-bit integers. I would like to send these to

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.