Crate string_calc
source ·Expand description
string_calc is a collection of utilities to perform checked arithmetics on
&str, to counter against floating point errors. It supports (checked) addition,
subtraction, and multiplication. It does not support division due to the
nature of division’s ability to generate infinite amount of decimals.
If your calculations have too many decimal points such that it can’t fit u128 range AFTER calculation, it’ll raise an error. If you pass in weird values that’s not integer or floats/decimals, it’ll raise an error. Return result will be Ok(String) which you can call .unwrap() or other methods to get its internal value, if everything goes right.
Functions
- Perform checked_add on floating points. Inherits the “checked_add” property of rust in integers. When failed, it’ll return Err(message). Success, Ok(value).
- Performs checked_mul on floating points. Inherits the checked_mul property of rust in integers. When failed, it’ll return Err(message). Success, Ok(value).
- Performs checked_sub on floating points. Inherits the checked_sub property of rust in integers. When failed, it’ll return Err(message). Success, Ok(value).