Help with Output Formatting

Why and how does this line output the following Input: float myFloat = 45.1342f; System.out.printf("%3.4e", myFloat); 4.5134+01 Very confused
No description
4 Replies
JavaBot
JavaBot7d ago
This post has been reserved for your question.
Hey @BraydnzWrld! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
dan1st
dan1st7d ago
Well that's what the 3.4e format specifier means. 3.4e means "ensure at least 3 letters (add spaces at the beginning if necessary)", "use 4 digits after the decimal point", "use scientific notation" (e) In this case, the 3 is pretty unnecessary as you should always have more digits and scientific notation means you always have one digit before the decimal point (except for +-0, NaN and +-Infinity)
JavaBot
JavaBot7d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?