最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript - Moving decimal place to the right - Stack Overflow

programmeradmin3浏览0评论

I'm trying to get the decimal place to move to the right and give me at least a 2 digit whole number. I've got the places after the decimal figured out, but not before the decimal.

The input value is divided by 36 and it's supposed to result in a percentage.

There's a fiddle here...

$(function() {
    var output_element = $('#creditRemaining');

    $('#creditRemaining').keyup(function() {  
        updateTotal();
    });


    var updateTotal = function () {
      var input1 = parseInt($('#creditRemaining').val() || 0);
      $('#total').text((input1 / 36).toFixed(2) + "% Prorated");
    };

 });

Thoughts?

I'm trying to get the decimal place to move to the right and give me at least a 2 digit whole number. I've got the places after the decimal figured out, but not before the decimal.

The input value is divided by 36 and it's supposed to result in a percentage.

There's a fiddle here...

$(function() {
    var output_element = $('#creditRemaining');

    $('#creditRemaining').keyup(function() {  
        updateTotal();
    });


    var updateTotal = function () {
      var input1 = parseInt($('#creditRemaining').val() || 0);
      $('#total').text((input1 / 36).toFixed(2) + "% Prorated");
    };

 });

Thoughts?

Share Improve this question asked Oct 29, 2013 at 15:22 MillhornMillhorn 3,1767 gold badges45 silver badges92 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Multiply it by 100 and then use .toFixed(2)

Then this line looks like this:

$('#total').text(((input1 / 36)*100).toFixed(2) + "% Prorated");
发布评论

评论列表(0)

  1. 暂无评论