基金年化收益率计算器
```html
body {
fontfamily: Arial, sansserif;
margin: 20px;
}
h1 {
textalign: center;
}
.calculator {
maxwidth: 400px;
margin: 0 auto;
padding: 20px;
border: 1px solid ccc;
borderradius: 5px;
backgroundcolor: f9f9f9;
}
.formgroup {
marginbottom: 15px;
}
label {
fontweight: bold;
}
input[type="number"] {
width: 100%;
padding: 8px;
border: 1px solid ccc;
borderradius: 3px;
boxsizing: borderbox;
}
button {
width: 100%;
padding: 10px;
backgroundcolor: 4caf50;
color: white;
border: none;
borderradius: 3px;
cursor: pointer;
}
button:hover {
backgroundcolor: 45a049;
}
result {
margintop: 20px;
textalign: center;
}
基金年化收益计算器
function calculate() {
var initialInvestment = parseFloat(document.getElementById('initialinvestment').value);
var finalValue = parseFloat(document.getElementById('finalvalue').value);
var investmentPeriod = parseFloat(document.getElementById('investmentperiod').value);
if (isNaN(initialInvestment) || isNaN(finalValue) || isNaN(investmentPeriod)) {
alert('请输入有效数字!');
return;
}
if (investmentPeriod <= 0) {
alert('投资期间必须大于零!');
return;
}
var totalReturn = finalValue initialInvestment;
var annualizedReturn = ((Math.pow((finalValue / initialInvestment), (1 / investmentPeriod))) 1) * 100;
var resultElement = document.getElementById('result');
resultElement.innerHTML = '您的基金年化收益率为:' annualizedReturn.toFixed(2) '%,总收益为:' totalReturn.toFixed(2) ' 人民币';
}