[TYPO3-shop] Feature suggestion for Commerce
Peter Raykov
pr at hygrooptima.com
Fri Aug 4 10:11:56 CEST 2006
Hi all,
If a shop works international, the prices must be calculated with or
without different VATs and for different currencies. This makes the
calculated prices ugly like 213.04 and makes impossible to show prices
in the "supermarket" style like 59.99 or 1.95. The conventional round
function is useless, because the introduced by the rounding error is
different for small and big prices and can't be controlled easy.
Below is a small function written by me many years ago for MS Excel,
that rounds a price within defined tolerance (not digital places) and
optional formats the last digits in the "99" style (of course within the
tolerance).
IMHO a similar Commerce feature will be very useful.
Peter
'---------------------------------------------------------
Public Function RoundFlex(N As Double, Optional Tolerance As Variant,
Optional LastDigits As Variant) As Double
If N <> 0 Then
Dim K As Double, er As Single, L As Double
Dim LD As Double, Delta As Double
If IsMissing(Tolerance) Then
er = 0.01 'Default Tolerance is 1%
Else
er = CSng(Tolerance)
If er <= 0 Or er >= 1 Then Error.Raise 6 'Interval 0-1 only
End If
If IsMissing(LastDigits) Then
Delta = 0 'No supermarket style
Else
LD = CLng(LastDigits)
If LD < 1 Then Error.Raise 6
LD = Val("." + Str$(LD)) '<1
Delta = 1 - LD
er = er * LD 'to be in the tolerance
End If
K = 10 ^ Int(Log10(2 * Abs(N) * er))
LD = Sgn(N) * K * Delta
RoundFlex = K * Round(N / K + LD) - LD
Else
RoundFlex = 0
End If
End Function
More information about the TYPO3-project-tt-products
mailing list