-1
If you're like me (and/or use Windows), You should have found this issue quite disturbing.
You plug in a hard drive (2TB for my occasion), and realize it doesn't show as 2TB, but a bit smaller size which is clearly not 2TB.
Over some research, I found it was because of Microsoft's mistake. Mistyping Binary prefix as Decimal prefixes. (i.e. They typed 1TiB as 1TB)
So, I would like to see a Binary prefix to Decimal prefix program. Since this is a big problem (and some computers are literally toasters), You have to make your program as short as possible.
I/O
You will be given the size (positive real number, will not exceed 2ˆ16 when converted), and the unit (4 of them, KiB, MiB, GiB and TiB, each corresponds to 1024ˆ1, 1024ˆ2, 1024ˆ3 and 1024ˆ4 bytes)
You have to output the (decimal representation of) the size (rounded half-up to integer value), and the corresponding unit.
Examples
678 MiB => 711 MB
1.8 TiB => 2 TB
Tip: Google has a unit converter
2This needs more specification. What units do we have to handle? What number ranges? With what precision? – xnor – 2017-03-25T03:53:52.347
1@xnor precision is specified(rounded half-up to integer value), everything else is edited to specify – Matthew Roh – 2017-03-25T03:57:34.067
2Better, but there's more to specify. How much precision can the inputs be given with? Can they be negative? Can an input be given like
.15
?1.00
? What about outputs? There's a bunch of things like this to pin down. I'd suggest moving it to the sandbox. – xnor – 2017-03-25T04:01:13.5832Rounding an precision are different. You use fractional terabytes but entire megabytes in your examples. – Dennis – 2017-03-25T04:01:51.770
@Dennis Huh? I don't understand what you mean. – Matthew Roh – 2017-03-25T04:03:53.827
1Why is the first output 711 MB and not 710.9 MB? – Dennis – 2017-03-25T04:06:12.137
@Dennis specified: rounded half-up to integer value – Matthew Roh – 2017-03-25T04:06:58.787
So the output for 1.4 TiB would be 2 TB? – Dennis – 2017-03-25T04:08:32.547
@Dennis Yup. 1.4 TiB=> 1.5...TB => 2TB. – Matthew Roh – 2017-03-25T04:10:02.287
What would the output for 999 MiB be? – Dennis – 2017-03-25T04:18:44.497
@Dennis 1048 it is. – Matthew Roh – 2017-03-25T05:47:09.227
6TiB or not TiB, that is the question. – Neil – 2017-03-25T10:26:56.670
@SIGSEGV So we don't have to "jump" prefixes? You should clarify that in the challenge spec. – Dennis – 2017-03-25T19:28:38.373
10Calling the discrepancy "Microsoft's horrible mistake" is somewhat flamebait. All they're doing is maintaining backwards compatibility with what us old-timers (read: anyone in their 30s or up) grew up knowing as the standard. – Peter Taylor – 2017-03-25T20:24:35.257
1Yeah, I don't know anyone who actually calls 1024 bytes a "kibibyte". You read it Kilobytes. The existence of a decimal form/prefix at all is the real problem – mbomb007 – 2017-03-27T16:08:37.447