Conver to decimal value

Posted on 2006-04-22
Last Modified: 2006-11-18
I have a javascript result that I need converted to a decimal.  Here is the line:

worksheet.Total.value = parseInt(Innovator) + parseInt(MktLdr) + parseInt(MajorCompetitor) + parseInt(MinorCompetitor)

Your help is appreciated.

Question by:jcpatterson
    LVL 49

    Expert Comment

    You mean this?

    var v = parseFloat(Innovator) + parseFloat(MktLdr) + parseFloat(MajorCompetitor) + parseFloat(MinorCompetitor);
    worksheet.Total.value = v.getFixed(2);

    LVL 1

    Author Comment

    Hello Roonaan,

    Thanks for your reply.  You are onto what I am trying to do and that is converting to two decimal points.

    I applied your recommendation and IE returns: Object doesn't support this property or method

    Firefox debugger highlights the "worksheet.Total.value = v.getFixed(2)" line as the problem.

    Here is the entire script in case you need to see it:

    <script language="JavaScript">
    function Scores() {

    var iA1 = worksheet.A1.value
    var iA2 = worksheet.A2.value
    var iA3 = worksheet.A3.value
    var iA4 = worksheet.A4.value  
    var iB1 = worksheet.B1.value
    var iB2 = worksheet.B2.value
    var iB3 = worksheet.B3.value
    var iB4 = worksheet.B4.value  

    Innovator = parseInt(iA1) * parseInt(iB1)
    MktLdr = parseInt(iA2) * parseInt(iB2)
    MajorCompetitor = parseInt(iA3) * parseInt(iB3)
    MinorCompetitor = parseInt(iA4) * parseInt(iB4)

    var v = parseInt(Innovator) + parseInt(MktLdr) + parseInt(MajorCompetitor) + parseInt(MinorCompetitor)

     worksheet.Total.value = v.getFixed(2)

    Thanks, John
    LVL 49

    Accepted Solution

    Sorry, indeed it should be v.toFixed(2) rather than v.getFixed(2).

    LVL 1

    Author Comment

    Thanks for your help on a Saturday.


    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now