I have to calculate some percentages but I have to avoid using floats in Rust.
i have this data structure
let data = Vec<Identity, u64>
from this i can sum all the u64's to get a total which we'll call the total maturity
let total_maturity = data.iter().map(|(,b)| b).sum()
so now i have the total maturity across all of them. it should be fairly trivial to get the percentage of maturity for each neuron but how i do i express this.
With floats it would be simple and the resulting vec of percentages associated with a neuron would be like [0.3, 0.4, 0.1 ....]
I've heard of using integer math but im not sure how it really works.
You can simply multiply all your numbers by 100 before dividing them.
If you need more precision, you can multiply by a larger number. Just remember that you will need to reintroduce the decimal point if you ever need to display them or perform math on them.
If you want something more flexible, there is the rust_decimal crate.