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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:07:23+00:00 2026-05-26T20:07:23+00:00

nStr = 12.00; alert(typeof(nStr));// getting number x = nStr.split(‘.’); // Other than string Split

  • 0
nStr    =   12.00;
alert(typeof(nStr));// getting number
x = nStr.split('.');
// Other than string Split function Through an error,
nStr    =   12.00;
nStr    +=  '';
alert(typeof(nStr));// getting string
x       =   nStr.split('.');
x1      =   x[0];
x2      =   x.length > 1 ? '.' + x[1] : '';
alert(x1+x2);

//Expected Output is 12.00

I got the temp output coding ( its not optimized coding)

nStr += '';
x = nStr.split('.');
x1  = x[0];
x[1]= (x[1].length == 1) ? '.' + x[1] + '0' : '.' + x[1];
x2  = x.length > 1 ? x[1] : '.00';
alert(x1+x2);               //  12.00
  • 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-26T20:07:23+00:00Added an answer on May 26, 2026 at 8:07 pm

    12.00 is 12 you can’t change that fact.

    Looks like what you are after is the toFixed() method of JavaScript:

    nStr    =   12;
    alert(nStr.toFixed(2));
    

    This will alert “12.00” as you want. The number passed to the method determines how many digits after the decimal point will be displayed.

    Worth mentioning is that the toFixed method will also round numbers, for example if in the above example nStr will be 12.5283 it will show 12.53 in the alert.

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

Sidebar

Related Questions

function addCommas(nStr) { nStr += ''; var x = nStr.split('.'); var x1 = x[0];
I'm new to bison and I'm getting a conflicts: 1 shift/reduce error. Can anyone
Here i have a string which is split and each line is in a
<li> is kept by the set_input() function, After getting data by using a getJSON()
Here's my function: def check_form(request): if request.method == 'POST': form = UsersForm(request.POST) if form.is_valid():
I am getting the Collection was mutated while being enumerated exception when I am
consider this code: class TestClass { function __construct() { set_error_handler(array($this,'error_handler')); } function error_handler($errno,$errstr,$errfile,$errline,$errcontext) {
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
I have this response.write on my page function roundthecon() { document.write(Math.round(exchRate*Math.pow(10,2))/Math.pow(10,2)); } But it
I am creating a small search function on my site, this enables the search

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.