Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda