string-formatting

Show decimal of a double only when needed

人走茶凉 提交于 2019-12-30 02:34:56
问题 I got this problem with double (decimals). When a double = 1.234567 Then I use String.format("%.3f", myString); So the result is 1.234 But when my double is 10 The result will be 10,000 I want this to be 10 Is their a way to say that he only needs to show the decimals when it is "usefull"? I saw some posts about this, but that was php or c#, couldn't find something for android/java about this (maybe I don't look good). Hope you guys can help me out with this. Edit, for now I use something

ValueError: cannot switch from manual field specification to automatic field numbering

不羁的心 提交于 2019-12-30 01:47:12
问题 The class: class Book(object): def __init__(self, title, author): self.title = title self.author = author def get_entry(self): return "{0} by {1} on {}".format(self.title, self.author, self.press) Create an instance of my book from it: In [72]: mybook = Book('HTML','Lee') In [75]: mybook.title Out[75]: 'HTML' In [76]: mybook.author Out[76]: 'Lee' Please notice that I didn't initialize attribute 'self.press',while use it in the get_entry method.Go ahead to type in data. mybook.press = 'Murach'

Python SQL query string formatting

蓝咒 提交于 2019-12-29 10:35:22
问题 I'm trying to find the best way to format an sql query string. When I'm debugging my application I'd like to log to file all the sql query strings, and it is important that the string is properly formated. Option 1 def myquery(): sql = "select field1, field2, field3, field4 from table where condition1=1 and condition2=2" con = mymodule.get_connection() ... This is good for printing the sql string. It is not a good solution if the string is long and not fits the standard width of 80 characters

Python SQL query string formatting

五迷三道 提交于 2019-12-29 10:34:52
问题 I'm trying to find the best way to format an sql query string. When I'm debugging my application I'd like to log to file all the sql query strings, and it is important that the string is properly formated. Option 1 def myquery(): sql = "select field1, field2, field3, field4 from table where condition1=1 and condition2=2" con = mymodule.get_connection() ... This is good for printing the sql string. It is not a good solution if the string is long and not fits the standard width of 80 characters

Using Python String Formatting with Lists

淺唱寂寞╮ 提交于 2019-12-28 08:06:21
问题 I construct a string s in Python 2.6.5 which will have a varying number of %s tokens, which match the number of entries in list x . I need to write out a formatted string. The following doesn't work, but indicates what I'm trying to do. In this example, there are three %s tokens and the list has three entries. s = '%s BLAH %s FOO %s BAR' x = ['1', '2', '3'] print s % (x) I'd like the output string to be: 1 BLAH 2 FOO 3 BAR 回答1: print s % tuple(x) instead of print s % (x) 回答2: You should take

Does StringFormat feature of WPF Xaml work on Label.Content?

对着背影说爱祢 提交于 2019-12-28 06:27:30
问题 I have bind my Amount Label's Content Property to a decimal property via DataContext. I am trying to apply stringformat but see no effect. Does StringFormat feature work on Label controls ?? Please tell me on which controls does this feature work. BTW following is the code for the Label Control for whom i want to apply the currency formatting <Label Grid.Column="2" Content="{Binding Path=Amount, StringFormat={}{0:C}}" Height="23" HorizontalAlignment="Left" Margin="100,10,0,0" Name="tb"

How to control padding of Unicode string containing east Asia characters

ⅰ亾dé卋堺 提交于 2019-12-28 04:15:13
问题 I got three UTF-8 stings: hello, world hello, 世界 hello, 世rld I only want the first 10 ascii-char-width so that the bracket in one column: [hello, wor] [hello, 世 ] [hello, 世r] In console: width('世界')==width('worl') width('世 ')==width('wor') #a white space behind '世' One chinese char is three bytes, but it only 2 ascii chars width when displayed in console: >>> bytes("hello, 世界", encoding='utf-8') b'hello, \xe4\xb8\x96\xe7\x95\x8c' python's format() doesn't help when UTF-8 chars mixed in >>>

String formatting of a Double [duplicate]

假如想象 提交于 2019-12-28 02:49:11
问题 This question already has answers here : Precision String Format Specifier In Swift (30 answers) Closed 5 years ago . I can't seem to find a way to format a Double limiting the precision to just a couple of positions after the decimal point when presenting that in a label. Maybe I'm missing something major, but I couldn't find anything in the official documentation. Thanks in advance for the help! 回答1: There's no way to do this using String interpolation. You can find a good discussion about

Is there a way to programmatically convert VB6 Formatting strings to .NET Formatting strings?

ⅰ亾dé卋堺 提交于 2019-12-28 02:11:07
问题 Does anyone know of a good reference for VB6 format-strings? Does anyone know of a converter from VB6 formatting strings to .NET strings? I'm working on porting a large VB6 code base to .NET. It is a database centric piece of software, and the database itself holds VB6 format-strings which are later loaded and used to display other data in the database. My question, like this article, is how to port this. However the answer chosen for that question isn't adequate for my needs. I'm

Implementing String.Format() in VB6

烈酒焚心 提交于 2019-12-27 17:29:09
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. Can String.Format() be implemented in VB6, at least a close-enough version of it that could be useful when programming in good ol' VB6? Good resource on the matter of VB6 string manipulation performance: http://www.aivosto.com/vbtips/stringopt2.html On a related not, I also came up with a couple string comparison