how to distribute a number based on scale table : i would like an algorithm to distribute a number into different classes based on

scale table


 * < $10,000  =>  13% 
    
 * $10,001 - $100,000  => 8% 
    
 * $100,001 - $1,000,000  => 6% 
    
 * $1,000,001 - $5,000,000  => 4.9% 
    
 * $5,000,000  => 3%



> if user enters $6,000,000
> 
> the expected output 
> 
> $10,000 * 13% = $1,300 
> 
> $90,000 * 8% = $7,200
> 
> $900,000 * 6% = $54,000 
> 
> $4,000,000 * 4.9% = $196,000
> 
> $2,000,000 * 3% =  $60,000
> 
> ------------------------ Total: $ $318,000
> 
> 


> if user enters $5,000
> 
> the expected output 
> 
> $10,000 = $5,000 + 13% = $650
> 
> $90,000 = 0 + 8% = $0
> 
> $900,000 = 0 + 6% = $0
> 
> $4,000,000 = 0 + 4.9% =  $0
> 
> $2,000,000 = 0 + 3% =  $0
> 
> --------------------------- Total = $650


