string-formatting

Javascript: why does this produce and ugly string??? I would like currency

只谈情不闲聊 提交于 2019-12-04 05:58:49
var total = 0; $(".amount").each(function() { var value = $(this).val(); value = (value.length < 1) ? 0 : value; var tmp = parseFloat(value).toFixed(2); total += tmp; }); $(".total").text(total); I am trying to loop through some text boxes and sum up their values. This produces a nasty string. What am I missing?? if I put 8 in the first textbox total text ends up as " 08.000.000.000.00". What am I doing wrong? I would like to format as currency but if not, at least just a two decimal number. Any pointers? Thanks, ~ck in San Diego .toFixed converts the object from a Number to a String. Leave

Using Html.fromHtml to set custom Typeface

坚强是说给别人听的谎言 提交于 2019-12-04 05:55:25
I found this list of HTML-Tags that are (supposedly) supported for HTML.fromHtml to create a Spanned-Text: http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html Now is there ANY way to set a custom Typeface with the Font-Tag? Outdated. See other answers. No, there's no way to do so. You can take a look at the Html implementation . As you will see, the font tag supports size and color only. Simply use a <font> tag with a face attribute. This has been possible since at least Android 1.5 ( see source code ). The value of the face attribute will be passed to the

How to set variable precision for new python format option

China☆狼群 提交于 2019-12-04 05:28:54
问题 I am loving the new format option for strings containing variables, but I would like to have a variable that sets the precision through out my script and I am not sure how to do that. Let me give a small example: a = 1.23456789 out_str = 'a = {0:.3f}'.format(a) print(out_str) Now this is what I would want to do in pseudo code: a = 1.23456789 some_precision = 5 out_str = 'a = {0:.(some_precision)f}'.format(a) print(out_str) but I am not sure, if it is possibly and if it is possibly how the

TextBox with CurrencyFormat and PropertyChanged trigger doesn't accept text right

情到浓时终转凉″ 提交于 2019-12-04 05:22:42
问题 I have a TextBox in a WPF window bound to a dependency property of the window of type double (see below). Whenever the user types in the TextBox when The TextBox is empty, or All of the text is selected, the typed text is accepted incorrectly. For example: If I type a '5' in either of these scenarios, the resulting text is "$5.00", but the caret is located before the '5', after the '$'. If I try to type "52.1", I get "$2.15.00". <Window x:Class="WPF.MainWindow" xmlns="http://schemas.microsoft

How can I format a number as xxx-xx-xxxx?

做~自己de王妃 提交于 2019-12-04 05:08:28
I am querying social security number data from a stored procedure and I would like to format it as a social security number in my stored procedure. How can I format xxxxxxxxx like xxx-xx-xxxx in Oracle? SSN formatting with TO_CHAR SELECT TO_CHAR(012345678, '000g00g0000','nls_numeric_characters=.-') ssn from dual; SSN ----------- 012-34-5678 update: thanks to Gary for pointing out that the '0' format character should be used rather than the '9' to preserve leading zeroes. you could also use the concat operator || , which might be more readable. SUBSTR(data, 1, 3) ||'-'||SUBSTR(data, 4, 2)||'-'|

formatting email body using VBA

不羁的心 提交于 2019-12-04 04:51:48
问题 I have the following section of code, which is part of an automatic reply system im developing. As i understand it, it should format the body of the email with line breaks, but, as the attached screenshot shows, it doesnt. Can somebody point oput where im going wrong? With NewForward .Subject = "'TEST' Hazard report reciept number: HAZ" & IDnumber .To = strSender .BCC = "xxxxxxxxxxxx" .HTMLBody = "Please accept this email as confirmation that xxxx has received your road defect notification.

Why can't Python's string.format pad with “\\x00”?

匆匆过客 提交于 2019-12-04 04:16:35
I wanted to pad a string with null characters ("\x00"). I know lots of ways to do this, so please do not answer with alternatives. What I want to know is: Why does Python's string.format() function not allow padding with nulls? Test cases: >>> "{0:\x01<10}".format("bbb") 'bbb\x01\x01\x01\x01\x01\x01\x01' This shows that hex-escaped characters work in general. >>> "{0:\x00<10}".format("bbb") 'bbb ' But "\x00" gets turned into a space ("\x20"). >>> "{0:{1}<10}".format("bbb","\x00") 'bbb ' >>> "{0:{1}<10}".format("bbb",chr(0)) 'bbb ' Even trying a couple other ways of doing it. >>> "bbb" + "\x00"

SQL: Binary to IP Address

回眸只為那壹抹淺笑 提交于 2019-12-04 04:11:36
I'm trying to convert A binary IP to a human-readable IP SELECT HEX( `ip_bin` ) FROM `log_metadata` gives me 4333D26E000000000000000000000000 And SELECT INET_NTOA(0x4333D26E) gives me 67.51.210.110 So I tried: SELECT SUBSTRING( CONVERT(HEX(`ip_bin`), CHAR(32)), 1, 8 ) AS `A` , INET_NTOA( SUBSTRING( CONVERT(HEX(`ip_bin`), CHAR(32)), 1, 8 ) ) AS `B` , INET_NTOA(hex(`ip_bin`)) AS `C` , INET_NTOA(`ip_bin`) AS `D` FROM `log_metadata` But I only get +----------+------------+------------+---------+ | A | B | C | D | +----------+------------+------------+---------+ | 4333D26E | 0.0.16.237 | 0.0.16.237

Python 3 - using tuples in str.format() [duplicate]

陌路散爱 提交于 2019-12-04 03:41:06
This question already has answers here : Closed 5 years ago . What is the pythonic way to unpack tuples? [duplicate] (2 answers) I'm trying to use the str.format() method, and having some difficulties when my values are stored within a tuple. For example, if I do: s = "x{}y{}z{}" s.format(1,2,3) Then I get 'x1y2z3' - no problem. However, when I try: s = "x{}y{}z{}" tup = (1,2,3) s.format(tup) I get IndexError: tuple index out of range. So how can I 'convert' the tuple into separate variables? or any other workaround ideas? Martijn Pieters Pass in the tuple using *arg variable arguments call

C# string formatting and padding

若如初见. 提交于 2019-12-04 03:34:21
问题 Seems like this should be something straightforward, but I haven't been able to get it right. I've looked at http://idunno.org/archive/2004/14/01/122.aspx for reference. Example: I would like to print a table of double values, with each double output having 3 decimal precision, and take up 10 spaces (left aligned). Conceptually, I tried something like this, but it only works with precision OR padding, not both: foreach(line in lines) { foreach (double val in line) { Console.Write("{0:0.000,