

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Formatting a Negative Number Output with Parentheses in Java
A negative number output can be shown using the Formatter object −
Formatter f = new Formatter(); f.format("%12.2f", -7.598); System.out.println(f);
Try the below given code to format a Negative Number Output with Parentheses −
Formatter f = new Formatter(); f.format("%(d", -50); System.out.println(f);
The following is an example −
Example
import java.util.Formatter; public class Demo { public static void main(String args[]) { Formatter f = new Formatter(); f.format("% d", 50); System.out.println(f); // negative number inside parentheses f = new Formatter(); f.format("%(d", -50); System.out.println(f); } }
Output
50 (50)
- Related Questions & Answers
- Python - Output Formatting
- Explain output formatting PowerShell
- Generic output formatting in Python
- Sum a negative number (negative and positive digits) - JavaScript
- Format Output with Formatter in Java
- Special Syntax with Parentheses in Python
- How to use formatting with printf() correctly in Java?
- Java Program to Check Whether a Number is Positive or Negative
- Locale-specific formatting in Java
- String Formatting in Java using %
- Java Program to output fixed number of array elements in a line
- Negative number digit sum in JavaScript
- Change date formatting symbols in Java
- String Formatting with ToString in C#
- Convert a number into negative base representation in C++
Advertisements