COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### How to get a number with 2 decimal, whatever this number is ???

• Email
• Follow

```I have a number, result of a calculation, and i would
like to see it always with 2 decimals, weather my
result would be 1234 or 1234,6 or 1234,5678.

The problem is that for example, if the result is
1234 I get 1234 but I would like to get 1234,00

I'm sure something must exist to do that !

Any idea ?

Thx !!!

PS1:Tried already with Round function, but it only
works if I have 3 or more numbers after the decimal !

solution, but it isn't the right solution for me, but I won't get
into that to keep it short.
```
 0
Reply lenaj_lenaj 4/27/2005 12:22:30 AM

See related articles to this posting

```A number will never be anything other than what it is: if it contains
two decimal places (.02, .44, etc.), that's what you'll see. If there
is only one (.2, .4, etc.), that's what it is no matter how badly you
want the zero on the end. An integer doesn't have any decimal places,
never will.

You've actually answered the question yourself: in your layouts, you
format all of your number fields to display two decimal places. Even if
the program (FileMaker or a spreadsheet or anything else) provided for
universal formatting of all numbers as two decimal places, it is still
only formatting.

Matt

On 4/26/2005, Lenaj wrote:

> I have a number, result of a calculation, and i would
> like to see it always with 2 decimals, weather my
> result would be 1234 or 1234,6 or 1234,5678.
>
> The problem is that for example, if the result is
> 1234 I get 1234 but I would like to get 1234,00
>
> I'm sure something must exist to do that !
>
> Any idea ?
>
> Thx !!!
>
>
> PS1:Tried already with Round function, but it only
> works if I have 3 or more numbers after the decimal !
>
> PS2:I know about the menu "Format->Number..."
> solution, but it isn't the right solution for me, but I won't get
> into that to keep it short.
```
 0
Reply Matt 4/27/2005 1:09:41 AM

```In article <d2939f2f.0504261622.28d42c38@posting.google.com>,
lenaj_lenaj@yahoo.ca says...
> I have a number, result of a calculation, and i would
> like to see it always with 2 decimals, weather my
> result would be 1234 or 1234,6 or 1234,5678.
>
> The problem is that for example, if the result is
> 1234 I get 1234 but I would like to get 1234,00
>
> I'm sure something must exist to do that !
>
> Any idea ?

Run a script to convert the number to text, format it the way you want,
and save it in a text field.

>
> Thx !!!
>
>
> PS1:Tried already with Round function, but it only
> works if I have 3 or more numbers after the decimal !
>
> PS2:I know about the menu "Format->Number..."
> solution, but it isn't the right solution for me, but I won't get
> into that to keep it short.

Your really should get into why that isn't the right solution for you.
;)
```
 0
Reply 42 4/27/2005 2:19:14 AM

```
On 4/26/2005, 42 wrote:

> In article <d2939f2f.0504261622.28d42c38@posting.google.com>,
> lenaj_lenaj@yahoo.ca says...
> > I have a number, result of a calculation, and i would
> > like to see it always with 2 decimals, weather my
> > result would be 1234 or 1234,6 or 1234,5678.
> >
> > The problem is that for example, if the result is
> > 1234 I get 1234 but I would like to get 1234,00
> >
> > I'm sure something must exist to do that !
> >
> > Any idea ?
>
> Run a script to convert the number to text, format it the way you
> want, and save it in a text field.

It wouldn't have to be a script.

It could be a calc field (returned as text) that tests the contents of
the number field:

If there is no decimal point (number is an integer), append the point
and two zeros; if there is a point but only one character after it
(length after decimal = 1), append a zero.

But then, Whether it's a script or a calc, we end up with text instead
of a number. It seems a whole lot simpler to just format the number,
unless it is, in fact, text you want.

I'll second 42: Lenaj, please get into why formatting the number
display to two decimal places isn't the right solution.

Matt
```
 0
Reply Matt 4/27/2005 11:35:54 AM

```
On 4/27/2005, Matt Wills wrote:

> If there is no decimal point (number is an integer), append the point
> and two zeros; if there is a point but only one character after it
> (length after decimal = 1), append a zero.

Oops, forgot the oher possibility:

If there are more than two places in the number (length after decimal
>2) knock them off using a string manipulation like the left function.
```
 0
Reply Matt 4/27/2005 12:05:07 PM

```In article <uOKbe.7534\$WX.4073@trndny01>, "Matt Wills"
<nothanks@verizon.net> wrote:

> On 4/26/2005, 42 wrote:
>
> > In article <d2939f2f.0504261622.28d42c38@posting.google.com>,
> > lenaj_lenaj@yahoo.ca says...
> > > I have a number, result of a calculation, and i would
> > > like to see it always with 2 decimals, weather my
> > > result would be 1234 or 1234,6 or 1234,5678.
> > >
> > > The problem is that for example, if the result is
> > > 1234 I get 1234 but I would like to get 1234,00
> > >
> > > I'm sure something must exist to do that !
> > >
> > > Any idea ?
> >
> > Run a script to convert the number to text, format it the way you
> > want, and save it in a text field.
>
> It wouldn't have to be a script.
>
> It could be a calc field (returned as text) that tests the contents of
> the number field:
>
> If there is no decimal point (number is an integer), append the point
> and two zeros; if there is a point but only one character after it
> (length after decimal = 1), append a zero.
>
> But then, Whether it's a script or a calc, we end up with text instead
> of a number. It seems a whole lot simpler to just format the number,
> unless it is, in fact, text you want.
>
> I'll second 42: Lenaj, please get into why formatting the number
> display to two decimal places isn't the right solution.

The Format > Number option only formats the number on-screen and in
printouts. It's useless if you want to export the numbers in a specific
format - for that you need to format the number in a text field and
then export the text version instead.

I haven't got time to work out the calculation today, but if nobody
else beats me to it I'll do that over the weekend.

Hopefully helping harassed humans happily handle handiwork hardships  ;o)
```
 0

```Here's one that I use:

Int(Round(Amount,2)) & "." & Right("00" & Round(Amount,2) *100,2)

Lenaj wrote:
> I have a number, result of a calculation, and i would
> like to see it always with 2 decimals, weather my
> result would be 1234 or 1234,6 or 1234,5678.
>
> The problem is that for example, if the result is
> 1234 I get 1234 but I would like to get 1234,00
>
> I'm sure something must exist to do that !
>
> Any idea ?
>
> Thx !!!
>
>
> PS1:Tried already with Round function, but it only
> works if I have 3 or more numbers after the decimal !
>
> PS2:I know about the menu "Format->Number..."
> solution, but it isn't the right solution for me, but I won't get
> into that to keep it short.

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Howard Schlossberg              (818) 883-2846
FM Pro Solutions       Los Angeles, California

FileMaker 7 Certified Developer
Associate Member, FileMaker Solutions Alliance
```
 0
Reply Howard 4/28/2005 4:04:18 PM

```On Thu, 28 Apr 2005 09:04:18 -0700, Howard Schlossberg wrote:
>  Here's one that I use:
>
>  Int(Round(Amount,2)) & "." & Right("00" & Round(Amount,2) *100,2)

What for do you use Int(Round(Amount,2)) instead of Rount(Amount,0)?

Do you have any special need how to handle  0.50 and -0.50 to any
direction?

Further improvement: replace "." by "middle(1/10 , 2 , 1)" - we got
decimal comma in this country here ;-)

- Martin
```
 0
Reply Martin 4/29/2005 1:03:45 PM

```In article <slrnd74c5h.evt.t-use@ID-685.user.individual.de>, t-
use@gmx.net says...
> On Thu, 28 Apr 2005 09:04:18 -0700, Howard Schlossberg wrote:
> >  Here's one that I use:
> >
> >  Int(Round(Amount,2)) & "." & Right("00" & Round(Amount,2) *100,2)
>
> What for do you use Int(Round(Amount,2)) instead of Rount(Amount,0)?

Because 4.979 ultimately needs to be 4.98, not 5.98.

Hint: int(round(4.979,2)) = 4, while round(4.979,0) = 5

> Do you have any special need how to handle  0.50 and -0.50 to any
> direction?

Natural rounding towards zero, looks like its in effect.

> Further improvement: replace "." by "middle(1/10 , 2 , 1)" - we got
> decimal comma in this country here ;-)

That's pretty clever. :)
```
 0
Reply 42 4/29/2005 11:48:52 PM

```On Fri, 29 Apr 2005 23:48:52 GMT, 42 wrote:
>  In article <slrnd74c5h.evt.t-use@ID-685.user.individual.de>, t-
>  use@gmx.net says...
> > On Thu, 28 Apr 2005 09:04:18 -0700, Howard Schlossberg wrote:
> > >  Here's one that I use:
> > >
> > >  Int(Round(Amount,2)) & "." & Right("00" & Round(Amount,2) *100,2)
> >
> > What for do you use Int(Round(Amount,2)) instead of Rount(Amount,0)?
>
>  Because 4.979 ultimately needs to be 4.98, not 5.98.

>  Hint: int(round(4.979,2)) = 4, while round(4.979,0) = 5

True - but what for do you need the Round at all?
Int(4.979) would be 4 as desired.

But you are right about the track: The first and the second, matching
round will ensure that the same rounding effect will take place for the
int and decimals part.

Int (4.996) would be 4 while int(rount(4.996,2)) is 5 as desired: 5.00

Thanks,
Martin
```
 0
Reply Martin 5/2/2005 8:25:31 AM

```In article <slrnd7bovr.ks.t-use@ID-685.user.individual.de>, t-
use@gmx.net says...
> On Fri, 29 Apr 2005 23:48:52 GMT, 42 wrote:
> >  In article <slrnd74c5h.evt.t-use@ID-685.user.individual.de>, t-
> >  use@gmx.net says...
> > > On Thu, 28 Apr 2005 09:04:18 -0700, Howard Schlossberg wrote:
> > > >  Here's one that I use:
> > > >
> > > >  Int(Round(Amount,2)) & "." & Right("00" & Round(Amount,2) *100,2)
> > >
> > > What for do you use Int(Round(Amount,2)) instead of Rount(Amount,0)?
> >
> >  Because 4.979 ultimately needs to be 4.98, not 5.98.
>
> >  Hint: int(round(4.979,2)) = 4, while round(4.979,0) = 5
>

No offense intended, but your entire post is quite puzzling.

> True - but what for do you need the Round at all?

The question I answered was specifically in response to your question.
That is: why it needed to be int(round(x,2)) vs round(x,0). If you'd
asked why we needed round at all then I'd have answered differently, and
probably with an example like the one you provided below.

> Int(4.979) would be 4 as desired.

> But you are right about the track:  The first and the second, matching
> round will ensure that the same rounding effect will take place for the
> int and decimals part.

/shrug

I know.

I thought that the only thing that was giving you pause was that you
couldn't think of a situation where it would make a difference between
int(round(x,2)) and round(x,0) for the integer part. Its pretty clear
you need to use round.... as you demonstrate below:

> Int (4.996) would be 4 while int(rount(4.996,2)) is 5 as desired: 5.00

Which is correct, but this example *only* highlights the difference
between: int(round(x,2)) and int(x), (which is *not* what you orginally
asked). Moreover it *doesn't* explain why round(x,0) is not not
sufficient (which *is* what you originally asked), because:

round(x,0) also gives the correct result of 5.

The question you asked was: "What for do you use Int(Round(Amount,2))

I'm really quite puzzled as to why you are now explaining to me why you
couldn't use int(x).
```
 0
Reply 42 5/2/2005 5:40:02 PM

```On Mon, 02 May 2005 17:40:02 GMT, 42 wrote:
>  No offense intended, but your entire post is quite puzzling.

Sorry, it was just loud thinking.

> > But you are right about the track:  The first and the second, matching
> > round will ensure that the same rounding effect will take place for the
> > int and decimals part.
>
>  /shrug
>
>  I know.

I think so. It was just that your answer did not provide the full answer
yet, but the first step for me, concerning the full answer. Maybe this
was obvious to you - it wasn't for me.

>  I'm really quite puzzled as to why you are now explaining to me why you
>  couldn't use int(x).

Is 42 a pseudonym of Howard? It was not obvious to me that you knew his
conclusions at length. But maybe the problem was just too obvious so
that all of you had to come to the same conclusion  - which I do
understand by now, but which I missed before, not thinking far enough.

Sorry again,
Martin
```
 0
Reply Martin 5/3/2005 8:34:56 AM

```Probably not obvious.  When I originally posted the calc, it was
something I'd pulled out of my "toolbox".  I didn't explain it in that
post because it would have taken me way too much thought to figure out
why I'd done it that way in the first place.

Although it's ironic that the number '42' will all of a sudden become
relevant to my life later this week, it's definitely not my pseudonym.

Martin Trautmann wrote:
> On Mon, 02 May 2005 17:40:02 GMT, 42 wrote:
>
>> No offense intended, but your entire post is quite puzzling.
>
>
> Sorry, it was just loud thinking.
>
>
>>>But you are right about the track:  The first and the second, matching
>>>round will ensure that the same rounding effect will take place for the
>>>int and decimals part.
>>
>> /shrug
>>
>> I know.
>
>
> I think so. It was just that your answer did not provide the full answer
> yet, but the first step for me, concerning the full answer. Maybe this
> was obvious to you - it wasn't for me.
>
>
>> I'm really quite puzzled as to why you are now explaining to me why you
>> couldn't use int(x).
>
>
> Is 42 a pseudonym of Howard? It was not obvious to me that you knew his
> conclusions at length. But maybe the problem was just too obvious so
> that all of you had to come to the same conclusion  - which I do
> understand by now, but which I missed before, not thinking far enough.
>
> Sorry again,
> Martin

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Howard Schlossberg              (818) 883-2846
FM Pro Solutions       Los Angeles, California

FileMaker 7 Certified Developer
Associate Member, FileMaker Solutions Alliance
```
 0
Reply Howard 5/3/2005 4:15:51 PM

```In article <117f8tokjjh1l18@corp.supernews.com>,
howard@antispahm.fmprosolutions.com says...
> Probably not obvious.  When I originally posted the calc, it was
> something I'd pulled out of my "toolbox".  I didn't explain it in that
> post because it would have taken me way too much thought to figure out
> why I'd done it that way in the first place.
>
> Although it's ironic that the number '42' will all of a sudden become
> relevant to my life later this week, it's definitely not my pseudonym.

I'll second that I'm not Howard. :)

> > I think so. It was just that your answer did not provide the full answer
> > yet, but the first step for me, concerning the full answer. Maybe this
> > was obvious to you - it wasn't for me.

Yes, it was quite obvious to me what was going on, and regrettably it
struck me from the nature of your question that it was quite obvious to
you too, excepting that one detail you originally asked about of course.

> >
> >> I'm really quite puzzled as to why you are now explaining to me why you
> >> couldn't use int(x).
> >
> >
> > Is 42 a pseudonym of Howard? It was not obvious to me that you knew his
> > conclusions at length. But maybe the problem was just too obvious so
> > that all of you had to come to the same conclusion  - which I do
> > understand by now, but which I missed before, not thinking far enough.

Indeed I had to doublecheck that -you- were not Howard. :) As when you
elaborated on why int(x) also did not work it struck me as if it were
something Howard would have said to further explain why he did what he
did. And that's why I was puzzled.

> > Sorry again,

No apologies necessary on your part. It seems the only one who owes any
sort of apology would be me, for misunderstanding the extent of your
question, and assuming that you had already fully understood the
solution, save the one detail.

Cheers.
```
 0
Reply 42 5/3/2005 6:04:54 PM

13 Replies
906 Views

Similar Articles

12/6/2013 11:16:52 AM
page loaded in 42899 ms. (0)