format

Java Double to String conversion without formatting

百般思念 提交于 2019-12-17 16:32:12
问题 I have the number 654987. Its an ID in a database. I want to convert it to a string. The regular Double.ToString(value) makes it into scientific form, 6.54987E5. Something I dont want. Other formatting functions Ive found checks the current locale and adds appropriate thousand separators and such. Since its an ID, I cant accept any formatting at all. How to do it? [Edit] To clarify: Im working on a special database that treats all numeric columns as doubles. Double is the only (numeric) type

MPAndroidChart x-axis date/time label formatting

陌路散爱 提交于 2019-12-17 16:17:37
问题 Background For some charts in my app, I'm using the MPAndroidChart library. All horizontal axis' of my graphs are time based, they can span a full year, a month, a week, a day or span one hour. It always shows a full period, so January-December, Monday-Sunday, 0:00 - 24:00 etc. The value of the axis is always the epoch-timestamp (in seconds). Requirement I want the x-axis labels to follow these rules: at 1st of month in case of year span; at start of day in case of month or week span; on any

How to convert Milliseconds to date format in C#?

南笙酒味 提交于 2019-12-17 15:49:14
问题 In C# how can I convert Unix-style timestamp to yyyy-MM-ddThh:mm:ssZ? 回答1: Start by converting your milliseconds to a TimeSpan : var time = TimeSpan.FromMilliseconds(milliseconds); Now, in .NET 4 you can call .ToString() with a format string argument. See http://msdn.microsoft.com/en-us/library/system.timespan.tostring.aspx In previous versions of .NET, you'll have to manually construct the formatted string from the TimeSpan's properties. 回答2: new DateTime(numTicks * 10000) The DateTime(long

Python way of printing: with 'format' or percent form? [duplicate]

荒凉一梦 提交于 2019-12-17 15:26:52
问题 This question already has answers here : String formatting: % vs. .format (16 answers) Closed 4 years ago . In Python there seem to be two different ways of generating formatted output: user = "Alex" number = 38746 print("%s asked %d questions on stackoverflow.com" % (user, number)) print("{0} asked {1} questions on stackoverflow.com".format(user, number)) Is there one way to be preferred over the other? Are they equivalent, what is the difference? What form should be used, especially for

Formatting a string into columns using String Interpolation

牧云@^-^@ 提交于 2019-12-17 14:54:57
问题 I need to print doubles so that definite number of symbols (like 8) is allocated for string representation of value. Next words should start at same index from beginning of string in each string. Now I have: value: 0 test value: 0.3333333333333 test value: 0.5 test I need: value: 0 test value: 0.33333333 test value: 0.5 test Test code: double[] ar = new double[] { 0, (double)1 / 3, (double)1 / 2 }; string s = "test"; foreach (var d in ar) { Console.WriteLine($"value: {d} {s}"); } What should

How do positional arguments like “1$” work with printf()?

帅比萌擦擦* 提交于 2019-12-17 12:16:46
问题 By man I find printf("%*d", width, num); and printf("%2$*1$d", width, num); are equivalent. But IMO the second style should be the same as: printf("%*d", num, width); However via testing it seems man is right; why? 回答1: The relevant part of the POSIX specification of printf() defines this behaviour: Conversions can be applied to the n th argument after the format in the argument list, rather than to the next unused argument. In this case, the conversion specifier character % (see below) is

How do positional arguments like “1$” work with printf()?

空扰寡人 提交于 2019-12-17 12:16:12
问题 By man I find printf("%*d", width, num); and printf("%2$*1$d", width, num); are equivalent. But IMO the second style should be the same as: printf("%*d", num, width); However via testing it seems man is right; why? 回答1: The relevant part of the POSIX specification of printf() defines this behaviour: Conversions can be applied to the n th argument after the format in the argument list, rather than to the next unused argument. In this case, the conversion specifier character % (see below) is

Using printf with a non-null terminated string

 ̄綄美尐妖づ 提交于 2019-12-17 10:13:14
问题 Suppose you have a string which is NOT null terminated and you know its exact size, so how can you print that string with printf in C? I recall such a method but I can not find out now... 回答1: There is a possibility with printf, it goes like this: printf("%.*s", stringLength, pointerToString); No need to copy anything, no need to modify the original string or buffer. 回答2: Here is an explanation of how %.*s works, and where it's specified. The conversion specifications in a printf template

Python String Formats with SQL Wildcards and LIKE

我怕爱的太早我们不能终老 提交于 2019-12-17 09:51:24
问题 I'm having a hard time getting some sql in python to correctly go through MySQLdb. It's pythons string formatting that is killing me. My sql statement is using the LIKE keyword with wildcards. I've tried a number of different things in Python. The problem is once I get one of them working, there's a line of code in MySQLdb that burps on string format. Attempt 1: "SELECT tag.userId, count(user.id) as totalRows FROM user INNER JOIN tag ON user.id = tag.userId WHERE user.username LIKE '%%s%'" %

How to read from input until newline is found using scanf()?

谁说胖子不能爱 提交于 2019-12-17 09:34:20
问题 I was asked to do a work in C when I'm supposed to read from input until there's a space and then until the user presses enter. If I do this: scanf("%2000s %2000s", a, b); It will follow the 1st rule but not the 2nd. If I write: I am smart What I get is equivalent to: a = "I"; b = "am"; But It should be: a = "I"; b = "am smart"; I already tried: scanf("%2000s %2000[^\n]\n", a, b); and scanf("%2000s %2000[^\0]\0", a, b); In the 1st one, it waits for the user to press Ctrl + D (to send EOF) and