Java: Literal percent sign in printf statement
The percent sign is escaped using a percent sign:
System.out.printf("%s\t%s\t%1.2f%%\t%1.2f%%\n",ID,pattern,support,confidence);
The complete syntax can be accessed in java docs. This particular information is in the section Conversions
of the first link.
The reason the compiler is generating an error is that only a limited amount of characters may follow a backslash. %
is not a valid character.
Printf puts a percent sign after everything it prints
This is zsh
's way of telling you that the preceding command outputted a partial line and the shell terminated that line to give you a prompt on a new line.
You can disable this behavior by typing PROMPT_EOL_MARK=''
into the command prompt.
How to escape the % (percent) sign in C's printf
You can escape it by posting a double '%' like this: %%
Using your example:
printf("hello%%");
Escaping the '%' sign is only for printf. If you do:
char a[5];
strcpy(a, "%%");
printf("This is a's value: %s\n", a);
It will print: This is a's value: %%
How do I print the percent sign(%) in C?
Your problem is that you have to change:
printf("%");
to
printf("%%");
Or you could use ASCII code and write:
printf("%c", 37);
:)
Include literal % percent sign in printf formatting string
You're treating %
as part of the "string" that you're printf()'ing
Pass the actual numeric value as the argument to printf(), and include the percentage sign in the "mask" (it needs to be escaped with another %
character)
<?php printf( __( '%.0f%%' ), $mini_deck->rating_per ); ?>
How to add percent sign in string format?
write %
twice:
rate = 99.99
let str = String(format: "%.2f%%", rate)
How to put a literal percent sign (%) inside F#'s printf format strings?
If printfn "%%"
outputs two percent signs (%%
) instead of one percent sign (%
), then you have to update F# 3.1 to at least version 3.1.1.
If you are using Visual Studio 2013, you can do this via Tools → Extensions and Updates → Updates → Visual Studio Gallery → Visual FSharp Tools.
How to escape a percent sign in AWK printf?
All printfs
I know (and in C as per the C Standard) allow you to specify a literal percent with %%
.
The GNU docs you reference tell you about how to escape special characters in string literals. However, printf's first arg is interpreted as a format string, so the string literal escape mechanism is the wrong place to look. The proper place to look up is the printf specification (either for awk, or if all else fails, the C language).
Java: Literal percent sign in printf statement
The percent sign is escaped using a percent sign:
System.out.printf("%s\t%s\t%1.2f%%\t%1.2f%%\n",ID,pattern,support,confidence);
The complete syntax can be accessed in java docs. This particular information is in the section Conversions
of the first link.
The reason the compiler is generating an error is that only a limited amount of characters may follow a backslash. %
is not a valid character.
Related Topics
Upgrade SQLite Database from One Version to Another
When Onbindviewholder Is Called and How It Works
What Does '->' (Arrow) Mean in Gradle's Dependency Graph
Why Do We Have to Call Super in Android Sometimes
Android (Java) Simple Send and Receive with Server - Fast Setup Challenge
How to Make Edittext Not Focused When Creating Activity
Encrypt with Node.Js Crypto Module and Decrypt with Java (In Android App)
Getlocationonscreen() VS Getlocationinwindow()
Android: Why Setvisibility(View.Gone); or Setvisibility(View.Invisible); Do Not Work
How to Avoid Unnecessary Firestore Reads with Cache
Translating Ruby Encryption Code to Java
Python: How to Execute a Jar File Through a Python Script