How to format a Java double with printf example

preview_player
Показать описание
Do you need to format a double in Java to two decimal places with the printf function? Need to specify the width, decimal precision or even the use of a comma to group numbers by the thousands? If so, then this quick Java printf tutorial on floating-point numbers like the Java double and float is exactly what you need. It will show you how to use Java printf to format double and other floating-point values with the %f format specifier.
Рекомендации по теме
Комментарии
Автор

I have been working with exit sequences and formatting outputs a TON, strictly because typing "System.out" gets annoying after a while... I must have messed with 34-million ways to printf format a double in the middle of a string output for the past 3 hours. Then, I find out it is THIS easy!!! Ha! I love this stuff! Thank you a ton

Chim_
Автор

You literally made my headache go away for a homework assignment. Thank you sir; who do you think you are, I am.

Designed
Автор

Formatting Java floating point numbers with printf is cool, but to do really cool stuff check out the JDK's DecimalFormat class!

scrumtuous
Автор

Dude, you helped me so much in a level that you don't understand, thank you very much, I'm very gratefull, you're amazing

salkin