string-formatting

Do C++ formatting libraries generally fall back to *sprintf for numeric formatting?

核能气质少年 提交于 2019-12-07 22:07:07
问题 I am wondering whether "all" C++ formatting libraries eventually fall back to a *sprintf function to format numbers. I am asking this because: Looking at the iostreams library that comes with Visual C++, I can see that numbers input into a stream will eventuall be formatted with sprintf_s . Boost.Format just uses the available iostreams library as far as I can tell. FastFormat eventually uses vsprintf to format a number. So, are there iostreams implementations that do not use *sprintf and do

How to make sure all excel cells formatted as text in a column actually are

亡梦爱人 提交于 2019-12-07 21:55:02
问题 I have a column of content submitted by multiple users, generally pasted into a sheet, from multiple sources. This column has numbers that should always be formatted as text. In fact, no matter how this is done, there are always a few items that never have the indicator in the left corner warning that these are formatted as text (which we want to see in all cases) Checking the individual cell, it does show as formatted text, but in reality on an import into a datatable, if the indicator is

center a string by padding spaces up to a specified length

孤街浪徒 提交于 2019-12-07 18:29:38
问题 I have a vector of names, like this: x <- c("Marco", "John", "Jonathan") I need to format it so that the names get centered in 10-character strings, by adding leading and trailing spaces: > output # [1] " Marco " " John " " Jonathan " I was hoping a solution less complicated than to go with paste , rep , and counting nchar ? (maybe with sprintf but I don't know how). 回答1: Here's a sprintf() solution that uses a simple helper vector f to determine the low side widths. We can then insert the

Customize display of an enumeration class

不问归期 提交于 2019-12-07 18:26:15
问题 I'd like to customize the display of an enumeration class using matlab.mixin.CustomDisplay . If I have a regular (non-enumeration) class such as the following: classdef test < handle & matlab.mixin.CustomDisplay properties value end methods function obj = test(value) obj.value = value; end end methods (Access = protected) function displayScalarObject(obj) disp(['hello ', num2str(obj.value)]) end end end then everything works fine - for example, >> a = test(1) a = hello 1 But if I have an

Refer to the same parameter multiple times in a fmt.Sprintf format string

筅森魡賤 提交于 2019-12-07 17:58:46
问题 I have this function: func getTableCreationCommands(v string) string { return ` CREATE TABLE share_` + v + ` PARTITION OF share FOR VALUES IN (` + v + `); CREATE TABLE nearby_` + v + ` PARTITION OF nearby FOR VALUES IN (` + v + `); ` } It's a little wonky... is there a way to format the string using fmt.Sprintf ? Something like this: func getTableCreationCommands(v string) string { return fmt.Sprintf(` CREATE TABLE share_%v PARTITION OF share FOR VALUES IN (%v); CREATE TABLE nearby_%v

Java Date Parsing Timezone causing parse error

霸气de小男生 提交于 2019-12-07 17:29:51
问题 I'm receiving a ParseException with the following code and I can't seem to fix it: String date = "Tue Mar 13 2012 10:48:05 GMT-0400"; SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss zzzX"); //Tried zzzZ at the end as well System.out.println(format.parse(date)); If I take out the -0400 and the X (or Z) at the end of the SimpleDateFormat things work fine, but once it's in the code, it simply doesn't work. What symbol should I be using instead? I'm using Java 7. Here is

Precise definition of float string formatting?

旧时模样 提交于 2019-12-07 16:25:26
问题 Is the following behavior defined in Python's documentation (Python 2.7)? >>> '{:20}'.format(1e10) ' 10000000000.0' >>> '{:20g}'.format(1e10) ' 1e+10' In fact, the first result surprises me: the documentation indicates that not indicating the format type ('f', 'e', etc.) for floats is equivalent to using the general format 'g'. This example shows that this does not seem to be the case, so I'm confused. Maybe this is related to the fact that "A general convention is that an empty format string

Format Decimal 2 Places - no trailing zeroes

ぐ巨炮叔叔 提交于 2019-12-07 13:44:46
问题 The format: #,# formats my number but it rounds my decimals up. I need to keep my decimals. Is there a format for that? Thank you. 回答1: #,#.### Ad as many # s as needed. To always show decimal places, use 0 s instead. 回答2: You can truncate decimal places with (int)d If you need two decimals you can write (int)(100*d)/100.0 (int)(100*1.99999)/100.0 ==> 1.99 回答3: If you are trying to display it as a string, try this... yourVariable.ToString("{0:F2}"); This will format the string into a fixed

Java printff string only output formatting

烈酒焚心 提交于 2019-12-07 13:27:44
How do I format output by using printf. suppose i want to print following in formatter. testing testing testing testing testingggg testingggg testingggg testingggg I am not asking about using "\t", I am asking on printf style formatting? If some one can give me suggestion and example. Or may be link with example. I can do it to fit my need. I think you're looking for the Formatter class, which does printf-style formatting for Java. For example, applied to your input: StringBuilder sb = new StringBuilder(); Formatter formatter = new Formatter(sb, Locale.US); formatter.format("%1$-15s %2$-15s %3

Is there a way to convert C-format strings for C# -format strings in C#/.NET 2.0?

左心房为你撑大大i 提交于 2019-12-07 12:46:22
问题 So i would like to convert string like this: "Bloke %s drank %5.2f litres of booze and ate %d bananas" with a C# equivalent for .Format or .AppendFormat methods "Bloke {0} drank {1,5:f2} litres of booze and ate {2} bananas" sorry but i'm not sure if the C# version was correct but u got the idea. The solution does not have to be perfect but cover the basic case. Thanks & BR -Matti answered in my other question How to write C# regular expression pattern to match basic printf format-strings like