Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Subtract two quantities and split into fractional values

I'm having trouble coming up with a function for this sort of weird math operation I'm trying to accomplish. Say you have two quantities of a liquid in ounces. The two quantities can be broken up into only four different parts: 1oz, 32nds of 1oz, 64ths of 1oz, and 128ths of 1oz. For example theses two quantities could be:

OZ 32 64 128
2 22 - 3
1 10 - 1

I need to calculate the difference between these two quantities. This is easy to do by hand, but not so much programmatically. The expected result for this situation would be 1oz, 12/32, 0/64 and 2/128. I must end up with the quantities broken up into their smallest proponents, so 32/32 should roll over to be 1oz, etc. What is the best way to implement this?

Here’s what I’ve been attempting most recently (just converting to and from decimal):

  1. Convert the quantity to fraction (like time to decimal) oz + (b * (1/32)) + (c * (1/64)) + (d * (1/128)) = 2.7109375
  2. Take the whole number from the decimal: 2 = 2oz
  3. Calculate 32nds from the remaining decimal (0.7109375 * (64/1) = 22 32nds with a remainder of 0.75
  4. Try to calculate 64ths (should be zero), 0.75 * (64/1) = 48, which is incorrect.

This math is based on https://www.calculatorsoup.com/calculators/time/decimal-to-time-calculator.php

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!