26 lines
1.5 KiB
Dart
26 lines
1.5 KiB
Dart
/// The Missouri Highway Fuel Tax Refund rate per gallon — the basis for
|
|
/// [estimatedFuelRefund]. Set by Missouri law and subject to change at any
|
|
/// time; the UI Settings toggle that turns these estimates on says as much,
|
|
/// and this is deliberately the highway rate only (not the separate,
|
|
/// higher non-highway-use refund) since that's the one that applies to
|
|
/// ordinary vehicle fill-ups this app is built around.
|
|
const moHighwayFuelTaxRefundRatePerGallon = 0.125;
|
|
|
|
/// A rough estimate of the Missouri Highway Fuel Tax Refund for [gallons]
|
|
/// of fuel, at the current rate. Purely informational — not tax advice,
|
|
/// and not a substitute for confirming the actual claimable amount with
|
|
/// the Missouri Department of Revenue.
|
|
///
|
|
/// [gallons] is rounded to the nearest whole gallon *before* multiplying —
|
|
/// matching how the actual refund calculation works, rather than
|
|
/// multiplying the precise (fractional) logged amount. The result is then
|
|
/// rounded down to the nearest cent, never up, so this never overstates
|
|
/// what's actually claimable.
|
|
double estimatedFuelRefund(double gallons) {
|
|
final roundedGallons = gallons.roundToDouble();
|
|
final rawRefund = roundedGallons * moHighwayFuelTaxRefundRatePerGallon;
|
|
// The tiny epsilon guards against binary floating-point representation
|
|
// error nudging an exact cent value (e.g. 2.50) just under its true
|
|
// value and floor()ing it down a cent it doesn't actually owe.
|
|
return (rawRefund * 100 + 1e-9).floorToDouble() / 100;
|
|
}
|