I was refactoring some old code and came across the following line of code to convert bytes to GB.
decimal GB = KB / 1024 / 1024 / 1024;
Is
To make sure that the compiler pre-calculates the divisors:
decimal GB = KB / (1024 * 1024);
Note that you are actually calculating GiB (gibibyte), not GB (gigabyte). If you really want to calculate GB, that would be:
decimal GB = KB / (1000 * 1000);