标签: string-formatting

以科学计数法显示小数

我该如何显示:

十进制('40800000000.00000000000000')为'4.08E + 10'?

我试过这个:

>>> '%E' % Decimal('40800000000.00000000000000')
'4.080000E+10'
Run Code Online (Sandbox Code Playgroud)

但它有额外的0.

python string-formatting

143
推荐指数
7
解决办法
24万
查看次数

什么是Ruby相当于Python的`s ="你好,%s.%s在哪里?" %("约翰","玛丽")`

在Python中,这种用于字符串格式化的习惯用法很常见

s = "hello, %s. Where is %s?" % ("John","Mary")
Run Code Online (Sandbox Code Playgroud)

Ruby中的等价物是什么?

ruby python string-formatting

140
推荐指数
4
解决办法
8万
查看次数

使用毫秒将日期时间格式化为字符串

我希望datetime从日期开始有一个字符串,以毫秒为单位.这段代码对我来说很典型,我很想学会如何缩短它.

from datetime import datetime

timeformatted= str(datetime.utcnow())
semiformatted= timeformatted.replace("-","")
almostformatted= semiformatted.replace(":","")
formatted=almostformatted.replace(".","")
withspacegoaway=formatted.replace(" ","")
formattedstripped=withspacegoaway.strip()
print formattedstripped
Run Code Online (Sandbox Code Playgroud)

python datetime string-formatting

135
推荐指数
6
解决办法
27万
查看次数

Python:格式输出字符串,右对齐

我正在处理包含坐标x,y,z的文本文件

     1      128  1298039
123388        0        2
....
Run Code Online (Sandbox Code Playgroud)

每行使用分为3个项目

words = line.split()
Run Code Online (Sandbox Code Playgroud)

在处理数据之后,我需要在另一个txt文件中写回坐标,以便每列中的项目对齐(以及输入文件).每一行都由坐标组成

line_new = words[0]  + '  ' + words[1]  + '  ' words[2].
Run Code Online (Sandbox Code Playgroud)

std::setw()在C++中是否有类似的操纵器允许设置宽度和对齐?

python alignment string-formatting

133
推荐指数
7
解决办法
22万
查看次数

如果你在String.format中多次获得相同的参数怎么样?

String hello = "Hello";

String.format("%s %s %s %s %s %s", hello, hello, hello, hello, hello, hello);

hello hello hello hello hello hello 
Run Code Online (Sandbox Code Playgroud)

hello变量是否需要在对format方法的调用中重复多次,或者是否有一个简写版本,允许您指定一次应用于所有%s标记的参数?

java string string-formatting

124
推荐指数
4
解决办法
5万
查看次数

使用Java字符串格式格式化整数

我想知道是否有可能使用Java中的String.format方法给出一个前面的零整数?

例如:

1将成为001
2将成为002
...
11将成为011
12将成为012
...
526将保持为526
......等

目前我尝试了以下代码:

String imageName = "_%3d" + "_%s";

for( int i = 0; i < 1000; i++ ){
    System.out.println( String.format( imageName, i, "foo" ) );
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这在数字前面有3个空格.是否可以在数字前面加零?

java string-formatting number-formatting

122
推荐指数
3
解决办法
27万
查看次数

118
推荐指数
8
解决办法
51万
查看次数

Objective-C格式化布尔值的字符串?

什么格式化程序用于布尔值?

编辑:

例如:NSLog(@" ??", BOOL_VAL);,是什么??

string objective-c string-formatting nsstring

117
推荐指数
6
解决办法
9万
查看次数

如何将毫秒转换为人类可读的形式?

我需要将任意数量的毫秒转换为Days,Hours,Minutes Second.

例如:10天,5小时,13分钟,1秒.

time date string-formatting datetime-format

116
推荐指数
7
解决办法
15万
查看次数

使用StringFormat将字符串添加到WPF XAML绑定

我有一个WPF 4应用程序,其中包含一个TextBlock,它具有一个单向绑定到一个整数值(在这种情况下,温度为摄氏度).XAML看起来像这样:

<TextBlock x:Name="textBlockTemperature">
        <Run Text="{Binding CelsiusTemp, Mode=OneWay}"/></TextBlock>
Run Code Online (Sandbox Code Playgroud)

这适用于显示实际温度值,但我想格式化这个值,因此它包括°C而不是数字(30°C而不是30°).我一直在阅读有关StringFormat的文章,我看过几个这样的通用例子:

// format the bound value as a currency
<TextBlock Text="{Binding Amount, StringFormat={}{0:C}}" />
Run Code Online (Sandbox Code Playgroud)

// preface the bound value with a string and format it as a currency
<TextBlock Text="{Binding Amount, StringFormat=Amount: {0:C}}"/>
Run Code Online (Sandbox Code Playgroud)

不幸的是,我所看到的所有例子都没有在我试图做的事情中附加一个字符串到绑定值.我敢肯定它必须简单但我找不到任何运气.任何人都可以向我解释如何做到这一点?

c# data-binding wpf xaml string-formatting

114
推荐指数
3
解决办法
15万
查看次数