string-formatting

Format a Number to a specific QString format

谁都会走 提交于 2021-02-07 11:25:13
问题 I have a question about formatting a decimal number to a certain QString format. Basically, I have an input box in my program that can take any values. I want it to translate the value in this box to the format "+05.30" (based on the value). The value will be limited to +/-99.99. Some examples include: .2 --> +00.02 -1.5 --> -01.50 9.9 --> +09.90 I'm thinking of using a converter like this, but it will have some obvious issues (no leading 0, no leading + sign). QString temp = QString::number

Why is print(“text” + str(var1) + “more text” + str(var2)) described as “disapproved”?

余生颓废 提交于 2021-02-07 05:14:33
问题 Why is the code below termed 'age-old disapproved method' of printing in the comment by 'Snakes and Coffee' to Blender's post of Print multiple arguments in python? Does it have to do with the backend code/implementation of Python 2 or Python 3? print("Total score for " + str(name) + " is " + str(score)) 回答1: Adding many strings is disapproved because: it's not really readable, compared to the alternatives. it's not as efficient as the alternatives. if you have other types you have to

Floating Point fixed length Number formatting c#

笑着哭i 提交于 2021-02-05 09:40:58
问题 I want to format a floating point number as follows in C# such that the entire width of the floating point number in C# is a fixed length (python equivalent format specifier 6.2f) I do NOT want it to be padded with 0's on the left but padded with a white space 100.00 90.45 7.23 0.00 what I have tried so far string.Format({0:###.##},100); string.Format({0:###.##},90.45); string.Format({0:###.##},7.23); string.Format({0:###.##},0.00); but the output is incorrect 100 90.45 7.23 //nothing is

Passing character strings of different lengths to functions in Fortran

北战南征 提交于 2021-02-05 07:18:12
问题 I am using Fortran 90 with the gfortran compiler as part of cygwin. I want to write a function that will create a series of new folders into a directory that is also passed as a parameter along with a number that is the maximum number of new consecutively numbered folders. Since I have to declare the length of the characters (ie strings) but also want to universally be able to pass different paths, I tried to pass the trimmed strings to the function. program main implicit none character(len =

Is there a simple and preferred way of German number string formatting in Python?

老子叫甜甜 提交于 2021-02-05 05:44:26
问题 I am searching for the proper way of German number formatting (e.g. 1.000,1234 ) in Python under Windows OS. I tried locale.setlocale but did not succeed. Instead, I have written a function to come up with the desired output. Is there a better way? def ger_num(number, precision=3): """ returns german formatted number as string or an empty string """ if number is not None: try: my_number = "{:,f}".format(number) except ValueError: return "" decimals, fraction = my_number.split(".")[0], my

Python: Formatting a string using variable names placeholders

我怕爱的太早我们不能终老 提交于 2021-02-04 14:53:25
问题 Consider the following string building statement: s="svn cp %s/%s/ %s/%s/" % (root_dir, trunk, root_dir, tag) Using four %s can be confusing, so I prefer using variable names: s="svn cp {root_dir}/{trunk}/ {root_dir}/{tag}/".format(**SOME_DICTIONARY) When root_dir , tag and trunk are defined within the scope of a class, using self.__dict__ works well: s="svn cp {root_dir}/{trunk}/ {root_dir}/{tag}/".format(**self.__dict__) But when the variables are local, they are not defined in a dictionary

SimpleDateFormat leniency leads to unexpected behavior

♀尐吖头ヾ 提交于 2021-02-04 07:19:07
问题 I have found that SimpleDateFormat::parse(String source)'s behavior is (unfortunatelly) defaultly set as lenient: setLenient(true). By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. If I set the leniency to false , the documentation said that with strict parsing, inputs must match this object's format. I have used paring with SimpleDateFormat without the lenient mode and by mistake, I

Haskell Display String into 8 columns

不问归期 提交于 2021-01-29 21:37:14
问题 I have type person = (String, Float, Float, [Int]) ** name, height, weight, miles walked past week** The [Int] will contain data for how many miles the person walked on each day for the past 7 days e.g. [5,8,12,7,12,6,9] My testData consists of multiple peoples data and I want to return all names and the 7 daily figures of the miles they walked as a single string, neatly into separate rows for each person and have the miles walked data lined up in columns. e.g. testData = [(John, 1.76, 63, [5

Trigger f-string parse on python string in variable

喜夏-厌秋 提交于 2021-01-29 09:11:01
问题 This question comes from handling jupyter magics , but can be expressed in a more simple way. Given a string s = "the key is {d['key']}" and a dictionary d = {'key': 'val'} , we want to parse the string. The old method would be .format() , which will raise an error - it doesn't handle dictionary keys. "the key is {d['key']}".format(d=d) # ERROR I thought the only way around was to transform the dictionary to an object (explained here or here). "the key is {d.key}".format(obj(d)) But Martijn

Format date with StringFormat in TextBlock in WPF

五迷三道 提交于 2021-01-29 06:30:47
问题 I have stored date in database without slashing for some reason . it means that I have a date field like 20110602. As i want to retrieve this date and show it in a textblock I need a formatting to show this date as a normal date with slash. How can i use StringFormat in this way ? ... does anyone konw what format should I use to convert "20110602" to 2011/06/02 ? <TextBlock Text="{Binding CreatedDate, StringFormat=?????" 回答1: If you perfer the route of implementing a converter: class