- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Python - Output Formatting
- Generic output formatting in Python
- Explain output formatting PowerShell
- Format Output with Formatter in Java
- How to use formatting with printf() correctly in Java?
- How do we do computer output formatting using the tag in HTML?
- Java Program to output fixed number of array elements in a line
- Locale-specific formatting in Java
- String Formatting in Java using %
- Special Syntax with Parentheses in Python
- Change date formatting symbols in Java
- Formatted Output in Java
- Java Program to Check Whether a Number is Positive or Negative
- Formatting Minute in m format in Java
- Formatting day in d format in Java

Advertisements