Display Negative Number in Parentheses in Java

In this post, we will see how to display negative number in Parentheses in Java.

We can use pattern #,##0.00;(#,##0.00) with DecimalFormat‘s format() to display negative number in Parenthesis in Java.


If you don’t need decimal places, you can change to pattern to:

Let’s understand meaning of pattern #,##0.00;(#,##0.00):

  • First part of up to semicolon is used to format positive numbers
  • Second part after semicolon is used to format negative numbers with parenthesis.

That’s all about how to display negative number in Parentheses in Java.

Was this post helpful?

Related Posts

  • 02 December

    Pass Variable From PHP to JavaScript

    Table of ContentsUse echo methodUse json_encode methodUse htmlspecialchars method Use echo method In order to pass variable from PHP to JavaScript, you will need to use the echo statement. This will print out the variable for you. For example, if you have a variable named $name, you would use the following code: [crayon-638b549ece4f8370224901/] This will […]

  • 02 December

    Remove Quotes from String in PHP

    Table of ContentsRemove Quotes from String in PhpUsing str_replace() MethodUsing preg_replace() MethodRemove Quotes from Beginning and End of String in PhpUsing trim() MethodUsing preg_Replace() Method Remove Quotes from String in Php Using str_replace() Method Use the str_replace() function to remove quotes from String in PHP. [crayon-638b549ece66e688491517/] [crayon-638b549ece671732944706/] We used str_replace() to remove double quotes and […]

  • 30 November

    Check if Array is Empty in PowerShell

    Table of ContentsWhat is an Empty Array?Use the Count Property to Check If an Array is Empty in PowerShellUse the Length Property to Check If an Array is Empty in PowerShell 💡TL;DR To check if an array is empty access its count property e.g. arr.count. If count is equal to 0, then array is empty. […]

  • 30 November

    Split Integer into Digits in Python

    Table of ContentsUsing List ComprehensionUsing for LoopUsing map() with list() & str.split() Using List Comprehension To split integer into digits in Python: Use the str() to transform the specified integer to a string. Use a list comprehension to loop over converted String. Use int() to convert every substring to an integer in each iteration. [crayon-638b549ece8cd230016874/] […]

  • 29 November

    Get Length of String in PowerShell

    Table of ContentsUsing String’s Length propertyUsing Measure-Object with Character parameter Using String’s Length property Use string’s length property to get length of String in PowerShell e.g. "Hello World".Length. System.String‘s Length property returns number of Characters present in the String. [crayon-638b549ece9ca581461265/] Output [crayon-638b549ece9cc833571800/] Here, we declared a string variable blog_Name which contains string Java2blog. We have […]

  • 29 November

    Prefix b Before String in Python

    Table of ContentsPrefix b Before String in PythonConclusion Prefix b Before String in Python Prefix b before String denotes a byte String. By putting b before String, you can convert String to bytes in Python. The upgrade from Python 2 to Python 3 was considered a major change as many new features were introduced and […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.