formatting

Formatting Numbers as Strings with Commas in place of Decimals

点点圈 提交于 2019-12-28 04:13:22
问题 I have the following number: 4.3 I'd like to display this number as 4,3 for some of our European friends. I was under the impression that the following line would do the trick: string ret = string.Format("{0:0,0}", 4.3); // returns "04", not "4,3" Am I using the incorrect string? 回答1: I think: string.Format(System.Globalization.CultureInfo.GetCultureInfo("de-DE"), "{0:0.0}", 4.3); should do what you want. 回答2: NumberFormatInfo nfi = new NumberFormatInfo(); nfi.NumberDecimalSeparator = ",";

Format output of $SimpleXML->asXML(); [duplicate]

ε祈祈猫儿з 提交于 2019-12-28 03:39:05
问题 This question already has answers here : PHP simpleXML how to save the file in a formatted way? (4 answers) Closed 2 years ago . The title pretty much says it all. If I have something like (from PHP site examples): $xmlstr = <<<XML <?xml version='1.0' standalone='yes'?> <movies></movies> XML; $sxe = new SimpleXMLElement($xmlstr); $sxe->addAttribute('type', 'documentary'); $movie = $sxe->addChild('movie'); $movie->addChild('title', 'PHP2: More Parser Stories'); $movie->addChild('plot', 'This

How to fmt.Printf an integer with thousands comma

一笑奈何 提交于 2019-12-28 02:39:17
问题 Does Go's fmt.Printf support outputting a number with the thousands comma? fmt.Printf("%d", 1000) outputs 1000 , what format can I specify to output 1,000 instead? The docs don't seem to mention commas, and I couldn't immediately see anything in the source. 回答1: None of the fmt print verbs support thousands separators. 回答2: Use golang.org/x/text/message to print using localized formatting for any language in the Unicode CLDR: package main import ( "golang.org/x/text/language" "golang.org/x

How can I set the decimal separator to be a comma?

 ̄綄美尐妖づ 提交于 2019-12-28 02:07:09
问题 I would like to read and write pi as 3,141592 instead of 3.141592 , as using the comma is common in many European countries. How can I accomplish this with iostream s? In other words cout << 3.141592; should print 3,141592 to standard output. 回答1: You should use basic_ios::imbue to set the preferred locale. Take a look here: http://www.cplusplus.com/reference/ios/ios_base/imbue/ Locales allow you to use the preferred way by the user, so if a computer in Italy uses comma to separate decimal

How can I set the decimal separator to be a comma?

久未见 提交于 2019-12-28 02:07:01
问题 I would like to read and write pi as 3,141592 instead of 3.141592 , as using the comma is common in many European countries. How can I accomplish this with iostream s? In other words cout << 3.141592; should print 3,141592 to standard output. 回答1: You should use basic_ios::imbue to set the preferred locale. Take a look here: http://www.cplusplus.com/reference/ios/ios_base/imbue/ Locales allow you to use the preferred way by the user, so if a computer in Italy uses comma to separate decimal

add commas to a number in jQuery

前提是你 提交于 2019-12-27 11:02:49
问题 I have these numbers 10999 and 8094 and 456 And all i want to do is add a comma in the right place if it needs it so it looks like this 10,999 and 8,094 and 456 These are all within a p tag like this <p class="points">10999</p> etc. Can it be done? I've attempted it here with the help of other posts http://jsfiddle.net/pdWTU/1/ but can't seem to get it to work Thanks Jamie UPDATE Messed around a bit and managed to figure it out here http://jsfiddle.net/W5jwY/1/ Going to look at the new

add commas to a number in jQuery

一世执手 提交于 2019-12-27 11:01:38
问题 I have these numbers 10999 and 8094 and 456 And all i want to do is add a comma in the right place if it needs it so it looks like this 10,999 and 8,094 and 456 These are all within a p tag like this <p class="points">10999</p> etc. Can it be done? I've attempted it here with the help of other posts http://jsfiddle.net/pdWTU/1/ but can't seem to get it to work Thanks Jamie UPDATE Messed around a bit and managed to figure it out here http://jsfiddle.net/W5jwY/1/ Going to look at the new

Question: Is There A Way To Format White-space Like This In C#?

半城伤御伤魂 提交于 2019-12-26 12:34:00
问题 Is There A Way To Format White-space Like This In C#? I would like to know if you could parse string arrays into a method and get it to return you a formatted string with white-spaces, there is a specific way i need this done so here's an example: string[][] StringArray = new string[][] { new string[] {"Name:", "John Jones."} new string[] {"Date of birth:", "07/11/1989."} new string[] {"Age:", "29 Years old."} }; FormatWhiteSpace(StringArray, Padding: 5); Output would be: Name: John Jones.

Question: Is There A Way To Format White-space Like This In C#?

淺唱寂寞╮ 提交于 2019-12-26 12:32:10
问题 Is There A Way To Format White-space Like This In C#? I would like to know if you could parse string arrays into a method and get it to return you a formatted string with white-spaces, there is a specific way i need this done so here's an example: string[][] StringArray = new string[][] { new string[] {"Name:", "John Jones."} new string[] {"Date of birth:", "07/11/1989."} new string[] {"Age:", "29 Years old."} }; FormatWhiteSpace(StringArray, Padding: 5); Output would be: Name: John Jones.

Remove newlines between two words

让人想犯罪 __ 提交于 2019-12-25 18:56:17
问题 I have a file that looks like: name: charles key1: how are you? name: erika key2: I'm fine, thanks name: ... How could I remove the new lines that between "key\d+" and "name:"? It should look like this: name: charles key1: how are you? name: erika key2: I'm fine, thanks name: ... I'm trying to use sed or awk but without any success. Is there any way to clean that lines? Is there any way to remove the newlines between "key\d+:" and "\w+:"? 回答1: something like this? kent$ awk '/^key.:/{p=1}/