C#: Storing percentages, 50 or 0.50?

后端 未结 5 1056
情书的邮戳
情书的邮戳 2021-02-19 10:53

When holding percentage values in variables is there a preference between holding them as whole numbers vs fractions. That is should the variable hold numbers between 0 and 100

5条回答
  •  故里飘歌
    2021-02-19 11:27

    You can use doubles to represent both percentages and 0-1. But if you choose to store percentage as "whole number" I would advise against using integers, which would limit you if you ever want to represent 12.3%, for example.

提交回复
热议问题