format

FileInputFormat where filename is KEY and text contents are VALUE

醉酒当歌 提交于 2019-12-10 15:46:12
问题 I'd like to use an entire file as a single record for MAP processing, with the filename as the key. I've read the following post: How to get Filename/File Contents as key/value input for MAP when running a Hadoop MapReduce Job? and while the theory of the top answer is solid, no code or "how-to" is actually provided. Here is my custom FileInputFormat and the corresponding RecordReader , which compile, yet do not produce ANY record data. Thanks for any help. public class CommentsInput extends

printf right align a bracketed number

送分小仙女□ 提交于 2019-12-10 15:26:58
问题 I'm writing a program that displays all the info in an array. It has to start with the array index in brackets (e.g. [2] ) and they have to be right aligned with each other. if it was just the number, I know that you can do: printf("%-10d", index); but putting brackets around that would give the following output [ 1] [ 2] ... [ 10] [ 11] when I really want it to be: [1] [2] ... [10] [11] How do I go about doing this? 回答1: Do it in two steps: first build a non-aligned string in a temporary

Java System.out.print formatting

一个人想着一个人 提交于 2019-12-10 15:12:12
问题 Here is my code (well, some of it). The question I have is, can I get the first 9 numbers to show with a leading 00 and numbers 10 - 99 with a leading 0. I have to show all of the 360 monthly payments, but if I don't have all month numbers at the same length, then I end up with an output file that keeps moving to the right and offsetting the look of the output. System.out.print((x + 1) + " "); // the payment number System.out.print(formatter.format(monthlyInterest) + " "); // round our

How to use CultureInfo to format deprecated currencies?

一世执手 提交于 2019-12-10 15:09:19
问题 In dotnet, the recommended way of formatting currencies in a culture-specific way, is (as far as I can find): using System.Globalization var info = CultureInfo.GetCultureInfo("en-GB") return string.Format(info, "{0:c}", 1234.5678) This returns: £1,234.57 However. No specific currency is given here. So if Great Britain ever converts to Euro, the same method would suddenly return something like: € 1,234.57 This has just happened to Latvia. This year, it converted to the euro. Various systems

Python Format Decimal with a minimum number of Decimal Places

孤者浪人 提交于 2019-12-10 15:01:33
问题 I have some Decimal instances in Python. I wish to format them such that Decimal('1') => '1.00' Decimal('12.0') => '12.00' Decimal('314.1') => '314.10' Decimal('314.151') => '314.151' hence ensuring that there are always at least two decimal places, possibly more. While there are no shortage of solutions for rounding to n decimal places I can find no neat ways of ensuring a lower bound on the number. My current solution is to compute: first = '{}'.format(d) second = '{:.2f}'.format(d) and

How to format a number with specified level of precision?

元气小坏坏 提交于 2019-12-10 14:22:38
问题 I would like to create a function that returns a vector of numbers a precision reflected by having only n significant figures, but without trailing zeros, and not in scientific notation e.g, I would like somenumbers <- c(0.000001234567, 1234567.89) myformat(x = somenumbers, n = 3) to return [1] 0.00000123 1230000 I have been playing with format , formatC , and sprintf , but they don't seem to want to work on each number independently, and they return the numbers as character strings (in

Golang string format using slice values

烂漫一生 提交于 2019-12-10 14:19:21
问题 Here I am trying to create a query string for my API from a slice containing strings. ie. where={"node_name":"node1","node_name":"node_2"} import ( "fmt" "strings" ) func main() { nodes := []string{"node1", "node2"} var query string for _, n := range nodes { query += fmt.Sprintf("\"node_name\":\"%s\",", n) } query = strings.TrimRight(query, ",") final := fmt.Sprintf("where={%s}", query) fmt.Println(final) } Here is goplayground link. What is the best way to get the result? 回答1: Your solution

Lisp format directive that interprets nil argument to empty string instead of “NIL”

落爺英雄遲暮 提交于 2019-12-10 14:18:13
问题 I know I can process the argument before passing it, I just wonder if there is a directive for this 回答1: CL-USER> (format nil "~@[~A~]" "foo") "foo" CL-USER> (format nil "~@[~A~]" nil) "" 来源: https://stackoverflow.com/questions/5729032/lisp-format-directive-that-interprets-nil-argument-to-empty-string-instead-of-n

Why am I receiving IllegalFormatConversionException in Java for this code?

穿精又带淫゛_ 提交于 2019-12-10 13:55:11
问题 I am currently working on a code that takes data from the network and print it out on a JTextArea. In between, I am trying to alignment the number based on the decimal position. This is the code that works before implementing the decimal alignment: private static final String NewLine = System.getProperty("line.separator"); String NetString = ""; byte[] data = p.getData(); NewString += "SID: " + BuildShort(data,4) + NewLine; NewString += "DID: " + BuildShort(data,6) + NewLine; And this is the

PHP : strtotime() returns always 01/01/1970

╄→гoц情女王★ 提交于 2019-12-10 13:48:02
问题 I am trying to display dates in the European format (dd/mm/yyyy) with strtotime but it always returns 01/01/1970. Here is my codeline : echo "<p><h6>".date('d/m/Y', strtotime($row['DMT_DATE_DOCUMENT']))."</h6></p>"; In my database, the field is a varchar and records are formated like yyyy.mm.dd I use the same codeline for another field that is formated like yyyy-mm-dd (varchar too) and it works fine. Thanks for your help. 回答1: Since the format yyyy-mm-dd works, try to replace . with - : date(