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 i128 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§

checked_add
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).
checked_mul
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).
checked_sub
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).
compare
Performs comparison between 2 values. When failed, it’ll return Err(message). Success, Ok(bool).
sum
Sum of all values given a Vec or Vec of valid items;