{"id":7122,"date":"2025-03-01T12:51:38","date_gmt":"2025-03-01T15:51:38","guid":{"rendered":"https:\/\/site.ocasteloforte.com\/?page_id=7122"},"modified":"2025-03-19T03:50:41","modified_gmt":"2025-03-19T06:50:41","slug":"simulador-de-juros-compostos","status":"publish","type":"page","link":"https:\/\/site.ocasteloforte.com\/en\/calculadora\/simulador-de-juros-compostos\/","title":{"rendered":"Simulador de Juros Compostos"},"content":{"rendered":"<div data-elementor-type=\"wp-page\" data-elementor-id=\"7122\" class=\"elementor elementor-7122\" data-elementor-post-type=\"page\">\n\t\t\t\t<div class=\"elementor-element elementor-element-f768e0f e-flex e-con-boxed e-con e-parent\" data-id=\"f768e0f\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-42a8a3e exad-sticky-section-no exad-glass-effect-no elementor-widget elementor-widget-html\" data-id=\"42a8a3e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div id=\"calculator\">\r\n    <h2>Simulador de Juros Compostos<\/h2>\r\n\r\n    <label for=\"initial_value\">Valor inicial<\/label>\r\n    <input type=\"text\" id=\"initial_value\" value=\"0,00\" oninput=\"formatInput(this)\" \/>\r\n\r\n    <label for=\"monthly_value\">Valor mensal<\/label>\r\n    <input type=\"text\" id=\"monthly_value\" value=\"0,00\" oninput=\"formatInput(this)\" \/>\r\n\r\n    <label for=\"interest_rate\">Taxa de juros (%)<\/label>\r\n    <input type=\"number\" id=\"interest_rate\" value=\"8\" step=\"0.1\" min=\"0\">\r\n    <select id=\"interest_type\">\r\n        <option value=\"yearly\">Anual<\/option>\r\n        <option value=\"monthly\">Mensal<\/option>\r\n    <\/select>\r\n\r\n    <label for=\"period\">Per\u00edodo<\/label>\r\n    <input type=\"number\" id=\"period\" value=\"1\" step=\"1\" min=\"1\">\r\n    <select id=\"period_type\">\r\n        <option value=\"years\">Ano(s)<\/option>\r\n        <option value=\"months\">M\u00eas(es)<\/option>\r\n    <\/select>\r\n\r\n    <div class=\"button-container\">\r\n        <button onclick=\"calculateCompoundInterest()\">Calcular<\/button>\r\n        <button onclick=\"resetCalculator()\">Limpar<\/button>\r\n    <\/div>\r\n\r\n    <div id=\"result\"><\/div>\r\n    <canvas id=\"chart\"><\/canvas>\r\n    <table id=\"resultTable\" border=\"1\">\r\n        <thead>\r\n            <tr>\r\n                <th>M\u00eas<\/th>\r\n                <th>Juros<\/th>\r\n                <th>Total Investido<\/th>\r\n                <th>Total Juros<\/th>\r\n                <th>Total Acumulado<\/th>\r\n            <\/tr>\r\n        <\/thead>\r\n        <tbody><\/tbody>\r\n    <\/table>\r\n<\/div>\r\n\r\n<script>\r\nfunction formatInput(input) {\r\n    let value = input.value.replace(\/\\D\/g, '');\r\n    value = (value \/ 100).toFixed(2).replace('.', ',');\r\n    input.value = value;\r\n}\r\n\r\nfunction calculateCompoundInterest() {\r\n    let initialValue = parseFloat(document.getElementById('initial_value').value.replace(\/\\D\/g, '') \/ 100);\r\n    let monthlyValue = parseFloat(document.getElementById('monthly_value').value.replace(\/\\D\/g, '') \/ 100);\r\n    let interestRate = parseFloat(document.getElementById('interest_rate').value) \/ 100;\r\n    let period = parseInt(document.getElementById('period').value);\r\n    let periodType = document.getElementById('period_type').value;\r\n    let interestType = document.getElementById('interest_type').value;\r\n\r\n    if (interestType === 'yearly') {\r\n        interestRate = interestRate \/ 12;\r\n    }\r\n\r\n    if (periodType === 'years') {\r\n        period *= 12;\r\n    }\r\n\r\n    let totalAmount = initialValue;\r\n    let totalInvested = initialValue;\r\n    let totalInterest = 0;\r\n    let tableBody = document.querySelector(\"#resultTable tbody\");\r\n    tableBody.innerHTML = \"\";\r\n    \r\n    let dataPoints = [];\r\n    \r\n    for (let i = 0; i < period; i++) {\r\n        let interestGained = totalAmount * interestRate;\r\n        totalAmount += monthlyValue + interestGained;\r\n        totalInvested += monthlyValue;\r\n        totalInterest += interestGained;\r\n        tableBody.innerHTML += `<tr><td>${i + 1}<\/td><td>R$ ${interestGained.toFixed(2).replace('.', ',')}<\/td><td>R$ ${totalInvested.toFixed(2).replace('.', ',')}<\/td><td>R$ ${totalInterest.toFixed(2).replace('.', ',')}<\/td><td>R$ ${totalAmount.toFixed(2).replace('.', ',')}<\/td><\/tr>`;\r\n        dataPoints.push({ x: i + 1, y: totalAmount });\r\n    }\r\n    \r\n    document.getElementById('result').innerHTML = `<h3>Resultado:<\/h3><p>Valor Final: R$ ${totalAmount.toFixed(2).replace('.', ',')}<\/p><p>Valor Investido: R$ ${totalInvested.toFixed(2).replace('.', ',')}<\/p><p>Total em Juros: R$ ${totalInterest.toFixed(2).replace('.', ',')}<\/p>`;\r\n    drawChart(dataPoints);\r\n}\r\n\r\nfunction resetCalculator() {\r\n    document.getElementById('initial_value').value = \"0,00\";\r\n    document.getElementById('monthly_value').value = \"0,00\";\r\n    document.getElementById('interest_rate').value = \"8\";\r\n    document.getElementById('period').value = \"1\";\r\n    document.getElementById('result').innerHTML = '';\r\n    document.querySelector(\"#resultTable tbody\").innerHTML = \"\";\r\n}\r\n\r\nfunction drawChart(dataPoints) {\r\n    let ctx = document.getElementById('chart').getContext('2d');\r\n    if (window.myChart) window.myChart.destroy();\r\n    window.myChart = new Chart(ctx, {\r\n        type: 'line',\r\n        data: {\r\n            labels: dataPoints.map(dp => dp.x),\r\n            datasets: [{\r\n                label: 'Total Acumulado',\r\n                data: dataPoints.map(dp => dp.y),\r\n                borderColor: 'blue',\r\n                fill: false\r\n            }]\r\n        },\r\n        options: {\r\n            responsive: true,\r\n            scales: {\r\n                x: { title: { display: true, text: 'M\u00eas' } },\r\n                y: { title: { display: true, text: 'Valor (R$)' } }\r\n            }\r\n        }\r\n    });\r\n}\r\n<\/script>\r\n\r\n<style>\r\n#calculator {\r\n    width: 1200px;\r\n    margin: 20px auto;\r\n    padding: 20px;\r\n    border: 1px solid #ccc;\r\n    border-radius: 10px;\r\n    background-color: #f9f9f9;\r\n}\r\n\r\n#calculator h2 {\r\n    text-align: center;\r\n}\r\n\r\n#calculator label {\r\n    display: block;\r\n    margin: 10px 0 5px;\r\n}\r\n\r\n#calculator input, #calculator select {\r\n    width: 100%;\r\n    padding: 8px;\r\n    margin-bottom: 10px;\r\n    border: 1px solid #ccc;\r\n    border-radius: 4px;\r\n}\r\n\r\n.button-container {\r\n    display: flex;\r\n    justify-content: space-between;\r\n}\r\n\r\n#calculator button {\r\n    width: 48%;\r\n    padding: 10px;\r\n    background-color: #0C163E;\r\n    color: white;\r\n    border: none;\r\n    border-radius: 5px;\r\n    cursor: pointer;\r\n}\r\n\r\n#calculator button:hover {\r\n    background-color: #2872FA;\r\n}\r\n\r\n#calculator button:nth-child(2) {\r\n    background-color: #808080;\r\n    color: black;\r\n}\r\n\r\n#calculator button:nth-child(2):hover {\r\n    background-color: #ffffff;\r\n}\r\n\r\ncanvas {\r\n    display: block;\r\n    margin: 20px auto;\r\n}\r\n\r\ntable {\r\n    width: 100%;\r\n    border-collapse: collapse;\r\n    margin-top: 20px;\r\n}\r\n\r\nth, td {\r\n    border: 1px solid black;\r\n    padding: 8px;\r\n    text-align: center;\r\n}\r\n<\/style>\r\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>Simulador de Juros Compostos Valor inicial Valor mensal Taxa de juros (%) AnualMensal Per\u00edodo Ano(s)M\u00eas(es) Calcular Limpar M\u00eas Juros Total Investido Total Juros Total Acumulado<\/p>","protected":false},"author":1,"featured_media":0,"parent":6749,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-7122","page","type-page","status-publish","hentry"],"blocksy_meta":{"has_hero_section":"disabled","styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":6}},"acf":[],"_links":{"self":[{"href":"https:\/\/site.ocasteloforte.com\/en\/wp-json\/wp\/v2\/pages\/7122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/site.ocasteloforte.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/site.ocasteloforte.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/site.ocasteloforte.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/site.ocasteloforte.com\/en\/wp-json\/wp\/v2\/comments?post=7122"}],"version-history":[{"count":0,"href":"https:\/\/site.ocasteloforte.com\/en\/wp-json\/wp\/v2\/pages\/7122\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/site.ocasteloforte.com\/en\/wp-json\/wp\/v2\/pages\/6749"}],"wp:attachment":[{"href":"https:\/\/site.ocasteloforte.com\/en\/wp-json\/wp\/v2\/media?parent=7122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}