0
double value = 4.507310875086383E-8;
System.out.printf("value is %f%n", value);
System.out.print("value is " + value + "\n");

The output:

value is 0.000000
value is 4.507310875086383E-8

I want to know how to output this number by using System.out.printf instead of concatenating strings

Hanabi
  • 577
  • 4
  • 9

2 Answers2

1

Here, you need to print 23 scale so you can do :

System.out.printf("value is %.23f%n", value);
Tom
  • 4,972
  • 3
  • 10
  • 28
-1

This question has been answered many times (see How to format strings in Java for example). There are many correct answers, one of them is using String.format():

jshell> String.format("value is %f", value)
$4 ==> "value is 4.507300"

From Java 15, you can also use String formatted method:

jshell> "%f is may value".formatted(value) 
$6 ==> "4.507300 is may value"