Jump to content

Using "()" for Negative Numbers


cosmic_sniper

Recommended Posts

Aside from money_format(), is there another way to use "()" instead of "-" for negative numbers?

 

Actually, using money_format() would be best for me but I've read somewhere that list of locale differ from server to server. Unfortunately, I cannot identify the list of locale supported on the server I'm using (Heliohost) since system('locale -a') is disabled.

 

Thanks in advance!

Link to comment
Share on other sites

It should be quite easy, but keep in mind adding brackets to an integer will convert it to a string, and be unusable with math operators.

 

Check if the value is less than zero, if it is, multiply it by -1 (or convert to string and strip the leading hyphen) and surround it in brackets.

 

<?php

$int = -500;

if( $int < 0 ) {
$int *= -1;
echo "($int)";
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.