Javascript tofixed

Javascript tofixed
0.0 0

#1
<html>

<head>
<style>
       table {
        border: 1px solid #666;
        width: 100%;
       }
       td {
        border: 1px solid black;
       }
</style>

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>

</head>

<body>

<div id="div1">
 <table id="tbl1">

 </table>
</div>

<script type="text/javascript">
function drawTable(data){
        for (var i = 0; i < data.length; i++){
            drawRow(data[i]);
        }
 }
function drawRow(rowData){
        var row = $("<tr />");
        $("#tbl1").append(row);
        row.append($("<td>" + rowData.id + ")</td>"));
        row.append($("<td>" + rowData.naam + "</td>"));
        row.append($("<td>" + rowData.perc * 100  + "</td>"));
 }
function loadBier() {
        $.getJSON( "https://15euros.nl/api/bier_basic.php",
            function( data ) {
                console.log("AJAX-data through jQuery:12", data);

                $("#div1").append( drawTable(data));
            }
        );
    }
    loadBier();
</script>

</body>
</html>

how do i add a .toFixed so the numbers will be with 2decimals
in the
row.append || rowData.perc


#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#4
(rowData.perc * 100).toFixed(2)

#5

thank you very much
appreciate it