There are still some questions unanswered. Write a program that tests these occu
ID: 3573199 • Letter: T
Question
There are still some questions unanswered. Write a program that tests these occurances to learn more about formatting. Submit the code and your answers.
What happens when:
You have more digits than your format describes.
(ie. 438.978 and "##.##")
You have fewer digits than your format describes
You remove decimal places, does the formatter round the number?
You use a string instead of a literal value to represent the format description (String format = "##.#"; DecimalFormat(format);)
Please use the java language. Thanks!!!
Explanation / Answer
Hi, Please find my answer for all questions.
Please let me know in case of any issue.
import java.text.DecimalFormat;
public class DecimalF {
public static void main(String[] args) {
String format = "##";
DecimalFormat df = new DecimalFormat(format);
double d = 438.478;
System.out.println(df.format(d));
}
}
/*
1. You have more digits than your format describes. (ie. 438.978 and "##.##")
Answer: it round up to specified number decimal point
for => 438.978 and "##.##" => 438. 98
2. You have fewer digits than your format describes
Answer: It print the number itself
for => 438.978 and "##.#######" => 438. 978
3. You remove decimal places, does the formatter round the number?
It print the number
for => 438 and "##.##" => 438
If you remove decimal place from formatter then it rounds up decimal point to whole number
for for => 438.978 and "##" => 439
for for => 438.478 and "##" => 438
for for => 438.778 and "##" => 439
*/