Skip to content
Advertisement

Tag: printf

What is the right printf syntax when formatting a double? [closed]

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 1 year ago. Improve this question I’m stuck at the printf statement. Can anyone tell, what’s the right syntax

C compatible printf output for Java

I’d want to convert float/double to string, in Java and C, such that the outputs are both consistent and user friendly. By “user friendly”, I mean the string should be human readable and sound: a maximum number of significant digits, and some automatic switching to scientific notation when appropiate (the double could span all the valid range). By “consistent” I

Java: Literal percent sign in printf statement

I’m trying to add an actual percent sign into a printf statement in Java and I’m getting the error: I can’t figure out how to put an actual percent sign into my printf? I thought using % to escape it would work, but it isn’t. Any ideas? Answer The percent sign is escaped using a percent sign: The complete syntax

What is the Java equivalent of C’s printf %g format specifier?

I tried using Formatter.format, but that seems to leave the mantissa on numbers with 0 mantissa, whereas the C version does not. Is there an equivalent of C’s %g format specifier in Java, and if not, is there a way to fake it? My intention is to preserve the mantissa exactly like C’s for compatibility reasons. foo.c Main.java Console: Similarly,

Advertisement