How to define formula for decimal places

83 Views Asked by At

I need to define a formula for a half unit of the smallest decimal place in unit price ($UP$), or understand if this can be defined with a formula?

What I have is this

$$ T_{min,max} = Amt +/- (Qty * NT)$$

Where

$T$ - Tolerated Amount
$Amt$ - Original Amount
$Qty$ - Original quantity
$NT$ - Half unit of the smallest decimal place in Unit Price ($UP$)

Examples of $NT$

$$UP = 2.456 {\implies} NT = 0.0005$$ $$UP = 2.4 {\implies} NT = 0.05$$ $$UP = 2.44500230012 {\implies} NT = 0.000000000005$$

How do I write formula to calculate $NT$?

1

There are 1 best solutions below

2
On

How are you presented with unit price? If it is a string that represents the decimal number, you can just count the characters past the decimal point and call it $n$. Then $NT=5\cdot10^{-(n+1)}$ If it is a floating point number, it is very hard, especially if your unit prices can have as many decimals as the last example. Floats can't represent all numbers exactly and fractions like $2.4_{10}$ don't terminate in binary, so detecting the number of places is difficult.