string-formatting

StringFormat with value zero

落爺英雄遲暮 提交于 2019-12-13 21:26:35
问题 I'm developing a wpf application with componentart I have a textblock like this <TextBlock FontSize="28" Text="{Binding DataPoint.Y, StringFormat=\{0:#\\%\}}" Foreground="Black"> As you can see, my StringFormat puts a '%' sign after the number, but if my data is 0.0 (I fill the component in code behind, my variable is a double) I get "%", but I want to get "0%", how can I do this? 回答1: you can use different StringFormat . Instead of 0:# put 0:0 : <TextBlock FontSize="28" Text="{Binding Path

String.Format Same Code Different View

為{幸葍}努か 提交于 2019-12-13 14:20:02
问题 I have a code like this; GridView1.FooterRow.Cells[11].Text = String.Format("{0:c}", sumKV) In my computer this code gives a result like that; But when I upload this code to my virtual machine it looks like this; TL means Turkish Liras. But I don't want to show the currency. I just want numbers. I also don't want to change the formating of numbers. (Like 257.579,02) How can I only delete TL in this code? 回答1: I would use this: var cultureWithoutCurrencySymbol = (CultureInfo)CultureInfo

printf a float value with precision (number of decimal digits) passed in a variable [duplicate]

耗尽温柔 提交于 2019-12-13 12:09:59
问题 This question already has answers here : Printf variable number of decimals in float (2 answers) Closed 3 years ago . I can print a float value with precision of 3 decimal digits with double f = 1.23456; printf( "%.3f", f ); Now I have the number of requested decimal digits that is not fixed but stored into a variable int precision; precision = atoi( argv[ 1 ] ); // ...just for example double f = 1.23456; How do I print the value of f with the number of decimal digits specified in precision ?

Format decimal value to currency with 2 decimal places [duplicate]

你。 提交于 2019-12-13 12:00:17
问题 This question already has answers here : How do I round a decimal value to 2 decimal places (for output on a page) (16 answers) Closed 5 years ago . I am getting data from a csv file and parsing it to my application. In my csv file I have a column price whose value I use as of course the price of an item in my project. However, the price in the csv file does not contain trailing 0s, For example, if the price of and item is $5.00 , the csv file has it as $5 , if the price is $9.60 , the csv

truncate and pad using format specification mini language

。_饼干妹妹 提交于 2019-12-13 11:45:11
问题 I'm currently writing code which pads a string with spaces, using Python's format specification mini language: print('''{user:<10}, you're welcome!'''.format(user='John Doe')) The output is: John Doe , you're welcome! However, if user's name is something like 'Joooooooooooohn Doe', I'd like to output: Jooooooooo, you're welcome! Is there a way to perform truncation AND padding using the format specification mini language? Thanks! 回答1: From the page you linked to: For non-number types

C formatted string - How to add leading zeros to string value using sprintf?

无人久伴 提交于 2019-12-13 11:02:25
问题 I want to add zeroes at the starting of a string. I am using format specifier. My input string is hello I want output as 000hello . I know how to do this for integer. int main() { int i=232; char str[21]; sprintf(str,"%08d",i); printf("%s",str); return 0; } OUTPUT will be -- 00000232 If I do the same for string. int main() { char i[]="hello"; char str[21]; sprintf(str,"%08s",i); printf("%s",str); return 0; } OUTPUT will be - hello (with 3 leading space) Why it is giving space in case of

Python: trouble reading number format

▼魔方 西西 提交于 2019-12-13 06:00:41
问题 I am reading from a file where numbers are listed as -4.8416932597054D-04, where D is scientific notation. I have never seen this notation before. How can Python read -4.8416932597054* D* -04 as -4.8416932597054* E* -04 I've looked at other question and haven't read anything that addresses this? (Or I have and didn't recognize it.) Thanks. 回答1: def to_float(s): return float(s.lower().replace('d', 'e')) Edit: Can you give an example of an input string that still gives you 'the same error'?

Print 2 ArrayLists with specific format

♀尐吖头ヾ 提交于 2019-12-13 03:49:48
问题 I am trying to format the output of my program, so it looks easily readable by the user. I am not that good at formatting text and I would really welcome your help. I am trying to print/display(in my JTextArea). I already have a method to display there: public void display(String... lines){ for(String line:lines){ System.out.println(line); } } Now, I have the 2 ArrayLists that contain some data which was added to them through the use of the program. itemOrders = new ArrayList<CafeOrders>();

String format printing with python3: How to print from array?

做~自己de王妃 提交于 2019-12-13 03:41:50
问题 Python3 has the super string.format printing: '{} {}'.format('one', 'two') If my strings are in an array, one way would be to type them out: a = ['one','two'] '{} {}'.format(a[0],a[1]) But how can I print from an array, instead of having to type out each element? For example, broken code: a = ['one','two'] '{} {}'.format(a) Gives me an expected error: IndexError: tuple index out of range Of course, playing with ','.join(a) won't help, because it gives one string rather than 2. (Or is there a

String format: Start scientific notation with 0. for positive number, with -. for negative number

限于喜欢 提交于 2019-12-13 02:41:38
问题 I want to format a list of numbers with a fixed exponential format: 0.xxxxxxxxxxxxEsee If the number is negative, the 0 should be substituted with a 0: -.xxxxxxxxxxxxEsee Can I accomplish this with a format string? E.g. output.write('{:+016.10E}{:+016.10E}{:+016.10E}\n'.format(a,b,c)) works nice, but does not fullfil the drop-the-zero requirement and also does give a leading 0. . An example output would be -.704411727284E+00-.166021493805E-010.964452299466E-020.229380762349E-07 -