human-readable

Java - Convert Human Readable Size to Bytes

僤鯓⒐⒋嵵緔 提交于 2019-11-28 03:19:28
问题 I've found lots of information about converting raw byte information into a human-readable format, but I need to do the opposite, i.e. convert the String "1.6 GB" into the long value 1717990000. Is there an in-built/well-defined way to do this, or will I pretty much have to roll my own? [Edit]: Here is my first stab... static class ByteFormat extends NumberFormat { @Override public StringBuffer format(double arg0, StringBuffer arg1, FieldPosition arg2) { // TODO Auto-generated method stub

iOS convert large numbers to smaller format

青春壹個敷衍的年華 提交于 2019-11-27 10:39:29
How can I convert all numbers that are more than 3 digits down to a 4 digit or less number? This is exactly what I mean: 10345 = 10.3k 10012 = 10k 123546 = 123.5k 4384324 = 4.3m Rounding is not entirely important, but an added plus. I have looked into NSNumberFormatter but have not found the proper solution, and I have yet to find a proper solution here on SO. Any help is greatly appreciated, thanks! Luca Iaco -(NSString*) suffixNumber:(NSNumber*)number { if (!number) return @""; long long num = [number longLongValue]; int s = ( (num < 0) ? -1 : (num > 0) ? 1 : 0 ); NSString* sign = (s == -1 ?

Natural/Relative days in Python

梦想与她 提交于 2019-11-27 07:25:09
I'd like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from "a moment ago", "a few minutes ago", "two hours ago", "three days ago", etc. Django 1.0 has a "humanize" method in django.contrib. I'm not using the Django framework, and even if I were, it's more limited than what I'd like. Please let me (and generations of future searchers) know if there is a good working solution already. Since this is a common enough task, I imagine there must be something. While not useful to you at this very moment, it may be so for future searchers: The babel

Make big and small numbers human-readable [duplicate]

那年仲夏 提交于 2019-11-27 03:06:51
问题 This question already has an answer here: Formatting Large Numbers with .NET 5 answers I would like to print my very small numbers in C# in a human friendly way, such as: 30µ for 3E-5 or 456.789n for 0.000000456789 . I know of the Humanize_number() function from BSD in C, but only compatible with bit ints, not floats and doubles. Is there the equivalent in C# that supports those? Also, it should keep a certain amount of precision when displaying numbers, like: 0.003596 should be displayed as

Converting file size in bytes to human-readable string

删除回忆录丶 提交于 2019-11-27 02:36:12
I'm using this function to convert a file size in bytes to a human-readable file size: function getReadableFileSizeString(fileSizeInBytes) { var i = -1; var byteUnits = [' kB', ' MB', ' GB', ' TB', 'PB', 'EB', 'ZB', 'YB']; do { fileSizeInBytes = fileSizeInBytes / 1024; i++; } while (fileSizeInBytes > 1024); return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i]; }; However, it seems like this isn't 100% accurate. For example: getReadableFileSizeString(1551859712); // output is "1.4 GB" Shouldn't this be "1.5 GB" ? It seems like the division by 1024 is losing precision. Am I totally

htop output to human readable file

你离开我真会死。 提交于 2019-11-27 02:06:05
问题 I've tried piping htop to a text file (e.g. htop > text.txt ) but it gives me text garbled by formatting strings (see below). Is there a way to get nicer, human readable output? ^[7^[[?47h^[[1;30r^[[m^[[4l^[[?1h^[=^[[m^[[?1000h^[[m^[[m^[[H^[[2J^[[1B ^[[36m1 ^[[m^[[1m[^[[m^[[32m||||||||||^[[31m||||||||||^[[30m^[[1m \ 22.2%^[[m]^[[m ^[[36mTasks: ^[[1m159^[[m^[[36m total, ^[[32m^[[1m5^[[m^[[36m running^[[3;3H2 ^[[m^[[1m[^[[30m \ 0.0%^[[m]^[[m ^[[36mLoad average: ^[[30m^[[1m1.11 ^[[m^[[m1.28 ^[

iOS convert large numbers to smaller format

眉间皱痕 提交于 2019-11-26 15:16:11
问题 How can I convert all numbers that are more than 3 digits down to a 4 digit or less number? This is exactly what I mean: 10345 = 10.3k 10012 = 10k 123546 = 123.5k 4384324 = 4.3m Rounding is not entirely important, but an added plus. I have looked into NSNumberFormatter but have not found the proper solution, and I have yet to find a proper solution here on SO. Any help is greatly appreciated, thanks! 回答1: -(NSString*) suffixNumber:(NSNumber*)number { if (!number) return @""; long long num =

Converting file size in bytes to human-readable string

前提是你 提交于 2019-11-26 12:34:54
问题 I\'m using this function to convert a file size in bytes to a human-readable file size: function getReadableFileSizeString(fileSizeInBytes) { var i = -1; var byteUnits = [\' kB\', \' MB\', \' GB\', \' TB\', \'PB\', \'EB\', \'ZB\', \'YB\']; do { fileSizeInBytes = fileSizeInBytes / 1024; i++; } while (fileSizeInBytes > 1024); return Math.max(fileSizeInBytes, 0.1).toFixed(1) + byteUnits[i]; }; However, it seems like this isn\'t 100% accurate. For example: getReadableFileSizeString(1551859712); /

Is there any rule of thumb to construct SQL query from a human-readable description?

落爺英雄遲暮 提交于 2019-11-25 22:57:39
问题 Whenever there is any description of query in front of us, we try to apply heuristics and brainstorming to construct the query. Is there any systematic step-by-step or mathematical way to construct SQL query from a given human-readable description? For instance, how to determine that, whether a SQL query would need a join rather than a subquery, whether it would require a group by, whether it would require a IN clause, etc.... For example, whoever studied Digital Electronics would be aware of