from Hacker News

Ask HN: Naming convention for a percentage stored as a value from 0 to 1

by escot on 2/15/24, 5:08 PM with 4 comments

Say you’re storing a percentage like “state tax”. You store it as a decimal: 0.4 means 40%. What do you call this type when you need to name a db column or a variable? Technically it is not a percent until you * 100.

“Decimal fraction” seems most correct but is very verbose. No one is writing taxRateDecimalFraction as a var name.

  • by warrenm on 2/15/24, 5:09 PM

    how about `taxrate`?

    Or don't store it as a decimal between 0 and 1 - but as a value between 0 and 100 (with possible decimal points, of course), and just call it `taxpct`?

  • by PaulHoule on 2/15/24, 5:09 PM

    Just "fraction".
  • by bell-cot on 2/15/24, 5:30 PM

    "rate", or "tax_rate", or "state_rate", or "state_tax_rate".
  • by warrenm on 2/15/24, 5:10 PM

    >No one is writing taxRateDecimalFraction as a var name.

    Wait til you see Java or Hungarian Notation