Dear Forum members,
Do we have a percentage function? I calculate everything in decimal and then multiply it by 100 to get a percentage value but I wanted to keep it as a percentage while multiplying it to other number.
For example:
0.315678 * 100 =31.5768% (also keeping it to 4 decimal places).
Now if i multiply this number with another value say 30.1234
31.5768% * 30.1234 - it should give me 9.512005771 instead of 951.2005771
I am really struggling with this as I am not sure how the number decimal precisions works.
Excel workbook can multiply the numbers using percentages and it’s not same even if i define the decimal places to 6 or 7, it starts giving me error.
Please if anyone can advise.
Hi,
Short answer - NO. CTL/Clover does not support any data type of type percentage.
Similarly to other languages - like Java, Python , etc. You need to calculate with percentages in their decimal number representation. There is no 31.5% which would somehow mean that it is actually 0.315 decimal.
However, I don’t see that as a big limitation. Just make sure if you are entering a value, and it is represented as a percentage, then divide it by 100. If you need to convert a result of a calculation to percentage, multiply it by 100.
Also, an important note. Since your examples have “decimal” numbers (literals) without D at the end - e.g. 0.315678D - you are actually using CTL’s “number” literals/variables for your calculations.
This is important to mention, as that means that all your calculations can use up to 15 decimal places. If you were using “decimal” numbers (literals) it would be up to 32. Important to keep in mind is also that calculations using CTL’s “decimal” are true decimals whereas “number” is approximation of decimal (this is quite complex topic and holds for most major programming languages).
Bottom line - if you are making any calculations where you count money (especially large amounts), use CTL’s “decimal” as that guaranties maximum precision and no danger of potential precision loss - e.g. 33.333D / 22.22D