Percentage change calculator written in rust
A percentage change is a way to express a change in a variable. It represents the relative change between the old value and the new one.
For example, if a house is worth $100,000 today and the year after its value goes up to $110,000, the percentage change of its value can be expressed as
It can then be said that the worth of the house went up by 10%.
In simple terms, there are three calculations that we carry out, here's an example:
- The first number minus the second number
- The sum of the previous calculation divided by the first number
- The sum of the previous calculation multipled by 100
- The answer is the percentage changed
50 - 10 = 40
40 / 50 = 0.8
0.8 * 100 = -8%
OR
100 - 200 = 100
100 / 200 = 0.5
0.5 * 100 = +50%
docker pull thomaschaplin/rust-percentage-change-calculator
docker run --rm thomaschaplin/rust-percentage-change-calculator <NUMBER> <NUMBER>
Make sure you have rust installed on your machine by following the getting started guide
- Clone this repository
git clone git@github.com:thomaschaplin/rust-percentage-change-calculator.git
- Change directory
cd rust-percentage-change-calculator
- Build the application
cargo build
- Run the application
cargo run <NUMBER> <NUMBER>
- Build the application in release mode
cargo build --release
- Execute the
rust-percentage-change-calculator
binary file found intarget/release/rust-percentage-change-calculator
./rust-percentage-change-calculator 100 200
+100%
./rust-percentage-change-calculator 200 100
-50%
./rust-percentage-change-calculator 100 100
0%
Build
docker build --rm -f Dockerfile -t thomaschaplin/rust-percentage-change-calculator .
Run
docker run --rm thomaschaplin/rust-percentage-change-calculator <NUMBER> <NUMBER>
Percentage graphic by Mario Rui from ClipArtKey.