Formula needed

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

I'm trying to calculate insurance fees for declared value rates. The
definition in the rate guide states this:

Declared Value Insurance Fee
<= $100.00 $0.00
$100 $0.60 for each $100 of the total value declared, with
a minimum charge of $1.80.

So here's the first few ranges:

0-100:0
100.01-300:1.80
300.01-400:2.40
400.01-500:3.00

I'm at a loss on creating a formula to figure this. Can anyone help?
 
This isn't elegant, but it should work:

Function InsuranceFee(ByVal declaredValue As Double) As Double
If declaredValue <= 100 Then Return 0
Dim dblTemp As Double = 0
dblTemp = 0.6 * declaredValue / 100
If dblTemp < 1.8 Then dblTemp = 1.8
dblTemp = Math.Round(dblTemp, 2) 'round to nearest cent
Return dblTemp
End Function

You might need to change the variable type from Double to Decimal or
whatever you are using.
 
Sorry, if you only add 60c each time, use this:

Function InsuranceFee(ByVal declaredValue As Double) As Double
If declaredValue <= 100 Then Return 0
Dim dblTemp As Double = 0
dblTemp = 0.6 * CDbl(CLng(declaredValue) \ 100)
If declaredValue Mod 100 > 0 Then
dblTemp += 0.6
End If
If dblTemp < 1.8 Then dblTemp = 1.8
dblTemp = Math.Round(dblTemp, 2) 'round to nearest cent
Return dblTemp
End Function
 
I'm trying to calculate insurance fees for declared value rates. The
definition in the rate guide states this:

Declared Value     Insurance Fee
<= $100.00             $0.00>  $100            $0.60 for each $100 of the total value declared, with

a minimum charge of $1.80.

So here's the first few ranges:

0-100:0
100.01-300:1.80
300.01-400:2.40
400.01-500:3.00

I'm at a loss on creating a formula to figure this. Can anyone help?

*** Sent via Developersdexhttp://www.developersdex.com***

Public Function CalculateRate(ByVal value as Double) As Double
If value > 100 Then
Return Math.Max(((value \ 100) + 1) * 0.60, 1.80)
End If
Return 0
End Function
 
In my tests I found that the rounding is going to be the most complex.

Dim DeclaredValue as Double = [...]
Dim InsuranceFee as Double = 0

If DeclaredValue > 100 AND DeclaredValue < 300.01 Then
InsuranceFee = 1.80
Else If DeclaredValue > 300
Dim Multiplier as Integer = Convert.ToInt32(DeclaredValue / 100)
If DeclaredValue > Multiplier * 100 Then
Multiplier += 1
End If
InsuranceFee = .6 * Multiplier
End If
 
Back
Top