Calculate number keeping it within range of 0.6 to 3.0

45 views Asked by At

I'm creating a tag cloud and trying to base each tags fontsize dynamically based on a the number of references a tag has.

So as a sample set:

car, 34
truck, 354
bike, 1230
bicycle, 3

With the above sample set I need to figure out each value as a value within a certain range of min 0.6 and maximum 3.0.

Taking 1230 as the max value and 1 as the minimum value.

The calculation I'm using is below but it seems to be inverted which I can't figure out, the outputted values are rounded.

car:

((1230 - 34) / (1230 - 1) * (3 - 0.6)) + 0.6
= 2.96

truck:

((1230 - 354) / (1230 - 1) * (3 - 0.6)) + 0.6
= 2.31

bike:

((1230 - 1230) / (1230 - 1) * (3 - 0.6)) + 0.6
= 0.6

bicycle:

((1230 - 3) / (1230 - 1) * (3 - 0.6)) + 0.6
= 3.0

Essentially, the higher the number the higher the value output up to a maximum of 3.0, all help appreciate.

0

There are 0 answers