The problem here is your method of attaining size doesn't match throughout your procedure. You initially set "len" to the [string length $value]. Then you set "unit" to to "($len-1) / 3". This where you make your mistake. This assumes 1,000 for our divisor. Yet below that you make use of the correct 1,024 to raise powers which throws off the entire equation. Using the method below should solve your problem and its more compact.
Could you verify that $value is indeed an integer and not a float?
The code posted by speechles relies on integer division, and will fail if either the nominator or the denominator is a float. I'd also recommend adding a constraint to the value of unit, as to prevent it from going out of bounds for the "suffix-list".
You might be able to get away with forcing $test to an integer in the beginning.