09-12-2022 05:15 AM
Hi
Is there a function or feature that will convert an integer or double value to an SI equivalent decimal string, but using 1024 as the divisor?
I.e
2^10 = 1024 (K)
2^20 = 1048576 (M)
2^30 = 1073741824 (G)
Etc
In other words -
0 < N < 1024 = "N"
1024 < N < 1048576 = "<N/1024> K"
1048576 < N < 1073741824 = "<N/1048576> M"
ETC
I'd be surprised if such a function does not exist. Or am I being naive?
Thanks
09-12-2022 06:59 AM
I don't know if it exists, but it's really not hard to do by yourself:
09-12-2022 07:23 AM - edited 09-12-2022 07:41 AM
Use an array of "",k,M,G,T and look up quotient of Log2(x),10 as the index.
Format "%f %sB" where f is Remainder log2(x), 10 and %s is the string from the Lookup table
09-12-2022 07:49 AM
@AeroSoul wrote:
I don't know if it exists, but it's really not hard to do by yourself:
That won't do it.
This kind of works, but the result is funky if the input is < 1024.
09-12-2022 08:23 AM
This works for practically anything, but i don't really like how it handles the decimal points.
JPB's idea, but i couldn't get his to work with the Remainder Log2(x), 10, so i did x/(1024^(log2(x)/10))
09-12-2022 09:06 AM
@AeroSoul wrote:
This works for practically anything, but i don't really like how it handles the decimal points.
JPB's idea, but i couldn't get his to work with the Remainder Log2(x), 10, so i did x/(1024^(log2(x)/10))
Well, that would be because I failed to describe the conversion correctly. CERTAINLY this was a problem with trying to type from my phone and not a failure to properly think through the math 🙂
I don't understand why x is not a Unsigned Integer in AeroSoul's picture of a snippet Last I checked Bytes can't be negative or fractional.
09-12-2022 07:21 PM - edited 09-12-2022 07:29 PM
Minor mod to add coverage for Peta and Exa (Zetta and Yotta are ignored since a U64 0xFFFFFFFFFFFFFFFF is a mere16EB-1Byte.) We need P and E to prevent indexing past the array size and making large numbers look small
09-20-2022 02:20 AM
@JÞB wrote:I don't understand why x is not a Unsigned Integer in AeroSoul's picture of a snippet Last I checked Bytes can't be negative or fractional.
Because right click--> create control on the log2(x) makes it a double 😄