EdgarsK Posted September 8, 2009 Report Share Posted September 8, 2009 Sveiki Man ir radusies neliela problēmiņa saskaitot naudu. <input type="radio" onclick="cad0(this.value);" value="Ls"> <input type="radio" onclick="cad0(this.value);" value="Eur"> <script type="text/javascript"> function cad0(val) { switch(val) { case "Ls": money="0.75"; break; case "Eur": money="0.55"; break; } // ir 5 vertibas pa 1 uz augšu price2 = money * 2; price3 = money * 3; price4 = money * 4; price5 = money * 5; saveinhtml('jdx-15-23-92',price); saveinhtml('jdx-15-23-93',price2); saveinhtml('jdx-15-23-94',price3); saveinhtml('jdx-15-23-95',price4); saveinhtml('jdx-15-23-96',price5); } </script> problēma ir sekojoša, ka javascript sareikina teiksim 0.521521 vai kautko tādu, bet jalietoju Math.Round tad attiecīgi paliek tikai 1 skaitlis. ka pareizi reikinat lai attiecigi javascriptaa price = 0,75 price2 buutu 1,50 price3 buutu 2,25 price4 buutu 3,00 price5 buutu 3,75 ? paldies jau ieprieksh Quote Link to comment Share on other sites More sharing options...
0 bubu Posted September 8, 2009 Report Share Posted September 8, 2009 Round(x*100)/100. Vēl tik pielikt pārbaudi, lai izvada trailing '0' simbolus. Kāpēc tu tajā switch'ā money piešķir stringu? Tālāk tu taču ar money mainīgo operē kā ar skaitlisku vērtību! Quote Link to comment Share on other sites More sharing options...
0 EdgarsK Posted September 8, 2009 Author Report Share Posted September 8, 2009 (edited) uj tiesham pareizi, paldies bubu par tiem stringiem. varbuut vari sikak nedaudz paradit to kodu ? pameiginaju man nesanaca. v2=Round((v*2)*100)/100; sanak ka itka izvada (1.2) butu jabut (1.25) Edited September 8, 2009 by EdgarsA Quote Link to comment Share on other sites More sharing options...
0 EdgarsK Posted September 8, 2009 Author Report Share Posted September 8, 2009 atradu kodu kurs man palidzeja. :) paldies function fam(mnt){ mnt -= 0; mnt = (Math.round(mnt*100))/100; return (mnt == Math.floor(mnt)) ? mnt + '.00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt); } Quote Link to comment Share on other sites More sharing options...
0 indoom Posted September 8, 2009 Report Share Posted September 8, 2009 (edited) vai arī funkciju Edited September 8, 2009 by indoom Quote Link to comment Share on other sites More sharing options...
Question
EdgarsK
Sveiki
Man ir radusies neliela problēmiņa saskaitot naudu.
problēma ir sekojoša, ka javascript sareikina teiksim 0.521521 vai kautko tādu, bet jalietoju Math.Round tad attiecīgi paliek tikai 1 skaitlis.
ka pareizi reikinat lai attiecigi javascriptaa
price = 0,75
price2 buutu 1,50
price3 buutu 2,25
price4 buutu 3,00
price5 buutu 3,75
? paldies jau ieprieksh
Link to comment
Share on other sites
4 answers to this question
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.