fnRoundTo function

dynamic fnRoundTo(
  1. dynamic v1,
  2. dynamic v2
)

Implementation

dynamic fnRoundTo(dynamic v1, dynamic v2) {
  final e = varToDouble(v1);
  final d = varToInt(v2);
  // WapForm's public-facing ROUND/ROUNDTO follows the spreadsheet
  // convention: a positive d means decimal places, negative means integer
  // places (e.g. ROUND(-50.55,-2) → -100). But mySimpleRoundTo follows
  // Delphi's native RoundTo convention, where the sign is exactly
  // inverted (Delphi's RoundTo(x,-2) is what actually means "round to 2
  // decimal places"), so the sign has to be flipped here first.
  return mySimpleRoundTo(e, -d);
}