techker Posted November 24, 2013 Share Posted November 24, 2013 Hey guys i have tried a few combinations with no luck... i have a tax cal for my invoice form but i need to round out the total not to have 1.23445 i have tried document.formname.Total.value = formname.Total.value.round (text1+text2+text3+text4+text5)* 0.14975 + (text1+text2+text3+text4+text5); document.formname.Total.value = Total.round (text1+text2+text3+text4+text5)* 0.14975 + (text1+text2+text3+text4+text5); ... any clue how? Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/ Share on other sites More sharing options...
Irate Posted November 24, 2013 Share Posted November 24, 2013 String does not have a method called round. Use Math.round(document.formname.Total.value) instead. Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/#findComment-1459759 Share on other sites More sharing options...
techker Posted November 24, 2013 Author Share Posted November 24, 2013 so i add it here? document.formname.Total.value = (text1+text2+text3+text4+text5)* 0.14975 + (text1+text2+text3+text4+text5); Math.round(document.formname.Total.value) Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/#findComment-1459760 Share on other sites More sharing options...
Irate Posted November 24, 2013 Share Posted November 24, 2013 Yeah, like that. Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/#findComment-1459761 Share on other sites More sharing options...
techker Posted November 24, 2013 Author Share Posted November 24, 2013 doesnt work? Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/#findComment-1459762 Share on other sites More sharing options...
Irate Posted November 24, 2013 Share Posted November 24, 2013 Alright, let's crack down this "problem". What exactly are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/#findComment-1459763 Share on other sites More sharing options...
techker Posted November 24, 2013 Author Share Posted November 24, 2013 So i have an invoice and it calculates tax.works fine but i need to round the decimals.so i don't get 12.1234$ i have this function calculate(){ if(isNaN(document.formname.f1.value) || document.formname.f1.value==""){ var text1 = 0; }else{ var text1 = parseInt(document.formname.f1.value); } if(isNaN(document.formname.f2.value) || document.formname.f2.value==""){ var text2 = 0; }else{ var text2 = parseFloat(document.formname.f2.value); } if(isNaN(document.formname.f3.value) || document.formname.f3.value==""){ var text3 = 0; }else{ var text3 = parseFloat(document.formname.f3.value); } if(isNaN(document.formname.f4.value) || document.formname.f4.value==""){ var text4 = 0; }else{ var text4 = parseFloat(document.formname.f4.value); } if(isNaN(document.formname.f5.value) || document.formname.f5.value==""){ var text5 = 0; }else{ var text5 = parseFloat(document.formname.f5.value); } document.formname.Total.value = (text1+text2+text3+text4+text5)* 0.14975 + (text1+text2+text3+text4+text5); Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/#findComment-1459764 Share on other sites More sharing options...
Irate Posted November 24, 2013 Share Posted November 24, 2013 (edited) I see. Try to do it like this, then. function calculate() { // your code here... document.formname.Total.value = Math.round((text1+text2+text3+text4+text5)*0.14975+(text1+text2+text3+text4+text5));That should do the trick. Edited November 24, 2013 by Irate Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/#findComment-1459766 Share on other sites More sharing options...
techker Posted November 24, 2013 Author Share Posted November 24, 2013 hey thx. it works but it rounds up all the total.. i just need to remove the last decimals. Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/#findComment-1459791 Share on other sites More sharing options...
kicken Posted November 24, 2013 Share Posted November 24, 2013 If you just want to truncate the number, use Math.floor(). That will just cut off the decimal without doing any rounding. Math.round does your traditional rounding based on what the decimal value is. Quote Link to comment https://forums.phpfreaks.com/topic/284205-round-total/#findComment-1459802 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.