Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi

i have 3numbers
First number :- 5133.60
Second number :- 2000.85
Third number :- 10.21

sum i want to get as "7144.66"

my problem is if i select this number "5133.60" it is taking only 5133 how to get full values .

my funcions is :-

C#
function getSum() {
            totalvalue = 0
            obj = document.myform.chkbox
             for (i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    totalvalue += parseInt(obj[i].value);
                 }

            }

            if (totalvalue == 0) {
                alert("Please select atleast one product!!");
                document.myform.totalsum.value = ""
            }
            else {
                document.myform.totalsum.value = totalvalue;
            }

        }
Posted
Comments
Sergey Alexandrovich Kryukov 30-Oct-12 0:26am    
Misleading title of the question: it has nothing to do with formatting (which is really some problem, may require 3rd-party code).
--SA

1 solution

You are using 'parseInt',which will take only integer part. So try to use 'parseFloat' method. Please check the modified code.

C#
function getSum() {
            totalvalue = 0
            obj = document.myform.chkbox
             for (i = 0; i < obj.length; i++) {
                if (obj[i].checked) {
                    totalvalue += parseFloat(obj[i].value);
                 }

            }

            if (totalvalue == 0) {
                alert("Please select atleast one product!!");
                document.myform.totalsum.value = ""
            }
            else {
                document.myform.totalsum.value = totalvalue;
            }

        }
 
Share this answer
 
Comments
Street Racers 30-Oct-12 0:22am    
please revert back if you face any issue.
Sergey Alexandrovich Kryukov 30-Oct-12 0:25am    
Correct, a 5.
For OP:
http://www.w3schools.com/jsref/jsref_parsefloat.asp
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900