Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda