Untitled
unknown
javascript
a month ago
991 B
0
Indexable
Never
// SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.20; contract PrecisionLoss2 { uint constant SMALLEST_RATE_PER_YEAR = 1; // 0.1% // 0.1% = 0.001 // 0.001,000,000,000,000,000 (to have 18 decimals, add 15 decimals) // 0.001,000,000,000,000,000,000,000,000 (to have 27 decimals, add 24 decimals) // (to have x decimals, add x-3 decimals - 3) function smallestRatePerSecond(uint decimals) public pure returns (uint) { return (SMALLEST_RATE_PER_YEAR * (10 ** (decimals - 3))); } // (1e18 * re18) / 1e18 = 1*r e18 // 1e18 * re27) // be18 * rex / 1ex function mulDiv18(uint balance, uint rateDecimals) external pure returns (uint) { return (balance * smallestRatePerSecond(rateDecimals)) / (365 days * (10 ** rateDecimals)); } // i = 289302916 (with biggest decimals possible) // what is the smalles amount of decimals with the same i? }
Leave a Comment