j143 / query-spanner-with-java

Querying cloud spanner with Java with testing CI on emulator
https://j143.github.io/query-spanner-with-java/
Apache License 2.0
1 stars 0 forks source link

java.util.IllegalFormatConversionException: d != java.lang.String #9

Closed j143 closed 3 years ago

j143 commented 3 years ago
Error: Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.String
    at java.base/java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4426)
    at java.base/java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:2938)
    at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:2892)
    at java.base/java.util.Formatter.format(Formatter.java:2673)
    at java.base/java.io.PrintStream.format(PrintStream.java:1053)
    at java.base/java.io.PrintStream.printf(PrintStream.java:949)
    at page.janardhan.labs.App.main(App.java:109)

https://github.com/j143/query-spanner-with-java/blob/c85902d722188f83a3e2fc244c51e1b68f7356a7/spanner-with-java/src/main/java/page/janardhan/labs/App.java#L108-L110

j143 commented 3 years ago

Conversion characters:

character type
%f decimal point accuracy of doubles
%d format spacing for integers
%c format spacing for characters
%s format Strings
%n adds a newline character (\n)
double d = 3.1415;
int i = 3;
char c = 'a';

String s = "Hello World";

System.out.printf("%.3f%n", d);

System.out.printf("<%3d>%n", i);

System.out.printf("%c%n", c);

System.out.printf("%s ", s);

[1] https://www.cs.colostate.edu/~cs160/.Summer16/worksheets/Week01/Printf.pdf