Urgent.News

What's breaking now, across thousands of outlets.

Tech

Rounding is a business rule: what your fee calculation actually charges

A fee calculator is mostly arithmetic, and the arithmetic is mostly correct. The part that produces support tickets is the last step: rounding. It looks like formatting. It is actually a business rule that decides whether the number on screen matches the number that was charged, and in a fee-heavy product those two disagree more often than anyone expects. Here is what rounding actually does in a…

A fee calculator's arithmetic is mostly correct, but the rounding step is where support tickets arise. This last step is actually a business rule that determines if the on-screen number matches the charged number, especially in fee-heavy products where discrepancies are more common than expected.

Rounding direction - half-up, half-even (banker's), ceiling, floor, truncation - varies by language and is influenced by ties and negative numbers, which often involve money when refunds are involved. However, this decision is not a technical choice, but a business decision that should be documented in the fee schedule alongside the rates, not hardcoded in the formatter.

If the rounding mode is stored in code while the rates are in the database, changing the rounding rule requires a deploy, and until that deploy, numbers are incorrect by a fraction of a basis point. Additionally, the order of operations also affects the result. Fees are often computed as amount * rate, then converted, rounded, and summed.

Each step is a potential rounding point, and early rounding may lose or invent money. It is crucial to keep full precision through the pipeline, rounding once at the boundary where the number becomes money, and per line item rather than summing first and then rounding, when charging per fill.

Floating point is not the enemy, but it can be a trap. For instance, 0.1 + 0.2 does not equal 0.3 because of the way floats handle precision. A subtler trap is mixing data types: applying a Decimal rate to a float amount can result in a float, eroding the precision that has been carefully preserved. To prevent this, parse amounts to Decimal from strings and never let a float enter the calculation.

Testing rounding is distinct from testing arithmetic. Traditional methods like assertEqual are insufficient, as they fail to catch the ties that often occur. Instead, test the tie case for each rounding mode, the negative case (since refunds round differently from charges under half-up), and the reconciliation case, ensuring the sum of rounded line items matches the reported total for a random batch of data. This final test uncovers real bugs by examining the invariant rather than individual numbers.

This issue is more critical than the rate itself. Users tend to compare rates and then scrutinize the total. If the rate is 0.08% but the total suggests 0.083%, the conversation shifts from rounding to trust. The fee page is where a trading product is most likely to be accused of wrongdoing, and rounding is usually the actual explanation.

Implementing a schedule with the rounding mode stored as data, using Decimal end-to-end, and reconciling per-line rounding against the total addresses the core issue. Previous notes in this series covered related problems, such as modeling fee schedules as data and maintaining consistency when changes occur infrequently. The key takeaway: rounding is a business rule, so store it with the rates, keep full precision until the money boundary, round per line item, reconcile the sum, and rigorously test the ties.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

How Do You Pick the Cover Frame for a Hit the Road Dude Clip? A Sharpness-and-Exposure Picker With ffmpeg and NumPy

When you post a Hit the Road Dude clip, the State Property meme where a driver at a pickup window repeats "State?" and sends someone off, the cover frame decides whether anyone taps it.

  • Sharpness determined by Laplacian variance of blurred frames
  • Exposure assessed by mean brightness and crushed pixel share
  • Frames from clip edges avoided, top timestamps printed for final decision

What makes a batch file rename safe to undo?

An Undo button is useful only if the application still knows what happened to each file—and can explain when going back is no longer possible. I build RenamerX, a desktop file renamer.

  • RenamerX shows original, proposed names and destination together
  • Preview catches mistakes early, like wrong dates or names
  • Undo requires mapping original to applied paths and operation outcomes

Turn Your Cursor Rules Into One Root AGENTS.md

Most of my repos still have Cursor rules in some form. Sometimes a dusty .cursorrules at the root. Sometimes a pile of .mdc files under .cursor/rules/ .

  • Gather existing Cursor rules from repositories
  • Organize information into standardized headings
  • Commit single source of truth root file

Custom payloads for the DJI Matrice 400: what can be integrated and how

Short answer: The DJI Matrice 400 is listed at about 9.74 kg with roughly 6 kg of payload and up to 59 minutes of flight time, which is enough to carry a Zenmuse gimbal and a second, custom payload at…

  • DJI Matrice 400 can carry 6 kg payload with 59-minute flight time
  • Custom payloads include 3D LiDAR, gas sensing, thermal imaging, broadcasting equipment
  • Successful integration requires balancing, power/data path, synchronized time data

Your agents are at home. You're at the office.

You kick off three agents on the Mac at home, then head to the office. Somewhere on the way one of them asks for permission to run a command, and it waits. The other two finish and wait too.

  • PonyMux 0.16 allows remote control of agents on Mac and Windows
  • Sign in with GitHub or Google to manage agents via web browser
  • Safely control agents with keystrokes, paste, drag, and send files

Move your Vapi assistants to a self-hosted server with no platform fee

Hosted voice-agent platforms add a per-minute fee on top of what you pay your speech-to-text, model, voice and phone providers.

  • Move Vapi assistants to self-hosted server with no platform fee
  • Dashboard at http://localhost:8000 for password and provider setup
  • Import account with assistants, tools, numbers via curl command

More from Tuesday 10 November →