Javascript afronden

Gestart doorShahiem4 reacties35 weergaven

5 berichten · pagina 1 van 1

Shahiem

Lid · Topicstarter

Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hi,

Ik ben bezig met een calculate systeem voor een winkelwagen maar ik wil het totaal bedrag afronden op 2 decimalen.

Maar het lukt niet echt. En het bedrag veranderd ook niet in google chrome.

<script type="text/javascript">
                
                            function changeVal(price)
                            {
                            
                                num = (price + [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$core[/COLOR][COLOR= #007700]->[/COLOR]entities[COLOR= #007700]([/COLOR][URL="http://www.php.net/number_format"]number_format[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$topal[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]2[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000].[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700]));[/COLOR] ?>);
                                document.getElementById(total).innerHTML = Math.round(num*1000)/1000;
                                
                            
                            }
                        </script>


Wie kan me helpen? smile
0
Berichten
35.796
Reputatie
1
Punten
0,00
Lid sinds
Laatst gezien
Wat staat er uiteindelijk in je (output-)broncode, dus met ingevulde PHP waarde?

En hoe roep je hem aan?
0
Shahiem

Lid · Topicstarter

Berichten
20.364
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Als ik bijvoorbeeld een product heb van: 2.95 en verzendkosten kies dan krijg ik : 6.4
En via me selectboox:

<select name="selects">
                                    <option disabled="disabled" selected="selected">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$language[/COLOR][COLOR= #007700]->[/COLOR]getLang[COLOR= #007700]([/COLOR][COLOR= #DD0000]choose[/COLOR][COLOR= #007700]);[/COLOR] ?></option>
                                    <option value="1" onclick="changeVal(2.95);">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$language[/COLOR][COLOR= #007700]->[/COLOR]getLang[COLOR= #007700]([/COLOR][COLOR= #DD0000]normalpostnl[/COLOR][COLOR= #007700]);[/COLOR] ?></option>
                                    <option value="2" onclick="changeVal(8.05);">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$language[/COLOR][COLOR= #007700]->[/COLOR]getLang[COLOR= #007700]([/COLOR][COLOR= #DD0000]normaltrnl[/COLOR][COLOR= #007700]);[/COLOR] ?></option>
                                    <option value="3" onclick="changeVal(3.45);">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$language[/COLOR][COLOR= #007700]->[/COLOR]getLang[COLOR= #007700]([/COLOR][COLOR= #DD0000]normalposteu[/COLOR][COLOR= #007700]);[/COLOR] ?></option>
                                    <option value="4" onclick="changeVal(8.05);">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$language[/COLOR][COLOR= #007700]->[/COLOR]getLang[COLOR= #007700]([/COLOR][COLOR= #DD0000]outside[/COLOR][COLOR= #007700]);[/COLOR] ?></option>
                                </select>
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Heb je een online voorbeeld? Iets waarbij we zien wat de uiteindelijke code is?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren