Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #8154
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Formatting a number |
| Date | 2013-01-30 16:38 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <keceei$4ar$1@dont-email.me> (permalink) |
| References | <ke7k5m$kc9$1@dont-email.me> <cfd3942e-e788-4e54-b999-3d22772692fa@f6g2000yqm.googlegroups.com> <ponfg8182jv66g3t4375jm3k2gfoq5f00l@4ax.com> <335ebd98-73e1-4d1a-bc03-c990d2cc03b0@r14g2000yqe.googlegroups.com> |
On 1/30/2013 2:05 AM, Captain Paralytic 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 like this one, tks. @cp
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Formatting a number Scott Johnson <noonehome@chalupasworld.com> - 2013-01-28 20:45 -0800
Re: Formatting a number Captain Paralytic <paul_lautman@yahoo.com> - 2013-01-29 02:19 -0800
Re: Formatting a number Scott Johnson <noonehome@chalupasworld.com> - 2013-01-29 05:28 -0800
Re: Formatting a number Richard Yates <richard@yatesguitar.com> - 2013-01-29 06:39 -0800
Re: Formatting a number Captain Paralytic <paul_lautman@yahoo.com> - 2013-01-30 02:05 -0800
Re: Formatting a number Richard Yates <richard@yatesguitar.com> - 2013-01-30 07:33 -0800
Re: Formatting a number Scott Johnson <noonehome@chalupasworld.com> - 2013-01-30 16:38 -0800
Re: Formatting a number The Natural Philosopher <tnp@invalid.invalid> - 2013-01-29 10:20 +0000
Re: Formatting a number Paul Herber <paul@pherber.com> - 2013-01-29 10:38 +0000
Re: Formatting a number Paul Herber <paul@pherber.com> - 2013-01-29 10:40 +0000
csiph-web