FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Formatting a number
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Formatting a number [message #180219 is a reply to message #180218] Wed, 30 January 2013 15:33 Go to previous messageGo to previous message
Richard Yates is currently offline  Richard Yates
Messages: 86
Registered: September 2013
Karma:
Member
On Wed, 30 Jan 2013 02:05:01 -0800 (PST), Captain Paralytic
<paul_lautman(at)yahoo(dot)com> wrote:

> On Jan 29, 2:39 pm, Richard Yates <rich...@yatesguitar.com> wrote:
>> On Tue, 29 Jan 2013 02:19:14 -0800 (PST), Captain Paralytic
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> <paul_laut...@yahoo.com> wrote:
>>> On Jan 29, 4:45 am, Scott Johnson <nooneh...@chalupasworld.com> wrote:
>>>> Hello
>>
>>>> I am looking if there is a better way to write the following if possible.
>>
>>>> I would like to display the negative sign in front of the dollar sign
>>>> when the unit is negative.
>>
>>>> if($units < 0){
>>>>         $f_units = '-$' . number_format($units * -1);} else {
>>
>>>>         $f_units = '$' . number_format($units);
>>
>>>> }
>>
>>>> I need $units to stay untouched since I am using it in a calculation
>>>> later down.
>>
>>>> Thanks
>>>> Scotty
>>
>>> How do you define "better". I can give you "other" ways to do it, but
>>> I have no idea what your criteria would be in deciding whether any of
>>> them are better.
>>
>>> Here's one:
>>> $f_units = (($units<0)?'-':'').number_format(abs($units));
>>
>> I think you mean:
>> $f_units = (($units<0)?'-$':'$').number_format(abs($units));
>
> Or I may have meant:
> $f_units = (($units<0)?'-':'').'$'.number_format(abs($units));

Yes, I thought of that one and wondered if there is any difference in
their efficiency, however small. I went with the first only because it
was fewer characters.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PEAR DB: "PHP Fatal error: Call to undefined method DB::query()"
Next Topic: cURL
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 04:40:51 GMT 2024

Total time taken to generate the page: 0.04453 seconds