Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #8140 > unrolled thread
| Started by | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| First post | 2013-01-28 20:45 -0800 |
| Last post | 2013-01-29 10:40 +0000 |
| Articles | 10 — 5 participants |
Back to article view | Back to comp.lang.php
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
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Date | 2013-01-28 20:45 -0800 |
| Subject | Formatting a number |
| Message-ID | <ke7k5m$kc9$1@dont-email.me> |
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
[toc] | [next] | [standalone]
| From | Captain Paralytic <paul_lautman@yahoo.com> |
|---|---|
| Date | 2013-01-29 02:19 -0800 |
| Message-ID | <cfd3942e-e788-4e54-b999-3d22772692fa@f6g2000yqm.googlegroups.com> |
| In reply to | #8140 |
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));
[toc] | [prev] | [next] | [standalone]
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Date | 2013-01-29 05:28 -0800 |
| Message-ID | <ke8iqp$frj$1@dont-email.me> |
| In reply to | #8143 |
On 1/29/2013 2:19 AM, Captain Paralytic 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 originally wrote 'elegant' but I think you got the jest.
I like one liners as yours and forgot about the abs() function
Thanks.
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2013-01-29 06:39 -0800 |
| Message-ID | <ponfg8182jv66g3t4375jm3k2gfoq5f00l@4ax.com> |
| In reply to | #8143 |
On Tue, 29 Jan 2013 02:19:14 -0800 (PST), Captain Paralytic
<paul_lautman@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));
[toc] | [prev] | [next] | [standalone]
| From | Captain Paralytic <paul_lautman@yahoo.com> |
|---|---|
| Date | 2013-01-30 02:05 -0800 |
| Message-ID | <335ebd98-73e1-4d1a-bc03-c990d2cc03b0@r14g2000yqe.googlegroups.com> |
| In reply to | #8151 |
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));
[toc] | [prev] | [next] | [standalone]
| From | Richard Yates <richard@yatesguitar.com> |
|---|---|
| Date | 2013-01-30 07:33 -0800 |
| Message-ID | <v6fig893qgsjqcvksfulk760ad11pk4o1f@4ax.com> |
| In reply to | #8152 |
On Wed, 30 Jan 2013 02:05:01 -0800 (PST), Captain Paralytic
<paul_lautman@yahoo.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.
[toc] | [prev] | [next] | [standalone]
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Date | 2013-01-30 16:38 -0800 |
| Message-ID | <keceei$4ar$1@dont-email.me> |
| In reply to | #8152 |
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
[toc] | [prev] | [next] | [standalone]
| From | The Natural Philosopher <tnp@invalid.invalid> |
|---|---|
| Date | 2013-01-29 10:20 +0000 |
| Message-ID | <ke87pt$j3s$3@news.albasani.net> |
| In reply to | #8140 |
On 29/01/13 04:45, Scott Johnson 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
try printf or sprintf..
--
Ineptocracy
(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
[toc] | [prev] | [next] | [standalone]
| From | Paul Herber <paul@pherber.com> |
|---|---|
| Date | 2013-01-29 10:38 +0000 |
| Message-ID | <2k9fg819igo94i5f5cuk978lgmnr3dfblt@news.eternal-september.org> |
| In reply to | #8140 |
On Mon, 28 Jan 2013 20:45:09 -0800, Scott Johnson <noonehome@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.
Have you looked at money_format()
Might be available on all systems though.
--
Regards, Paul Herber, Sandrila Ltd.
http://www.sandrila.co.uk/ twitter: @sandrilaLtd
[toc] | [prev] | [next] | [standalone]
| From | Paul Herber <paul@pherber.com> |
|---|---|
| Date | 2013-01-29 10:40 +0000 |
| Message-ID | <tm9fg8lko5712pr2cmm21nibt1mm0h4up0@news.eternal-september.org> |
| In reply to | #8146 |
On Tue, 29 Jan 2013 10:38:59 +0000, Paul Herber <paul@pherber.com> wrote:
>On Mon, 28 Jan 2013 20:45:09 -0800, Scott Johnson <noonehome@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.
>
>Have you looked at money_format()
>Might be available on all systems though.
^ not
--
Regards, Paul Herber, Sandrila Ltd.
http://www.sandrila.co.uk/ twitter: @sandrilaLtd
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web