Arithmetic operators

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Arithmetic operators

Jakub-8
Hello, i have one beginners problem:

                            pomPrice := (item value / 100) *  item price.   
                            Transcript show: 'Price is: '; show: pomPrice; cr.
result:
Price is: (1999/20)
item value is 5
item price is 1999

but i need value = number :)

thnx

--
Jakub.
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Arithmetic operators

cedreek
Hi,

asFloat, asInteger, rounded, truncated...

In your case I guess asFloat...

Also, in your operation that lead to a fraction, if you declare a
number as a float (but smalltalk way, you write it), the evalutaion
will result in a float...

(1999/20.00)  "print it"  instead of  (1999/20.00)

so (item value / 100.00)  for instance...

Cheers,
Cédrick

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Arithmetic operators

Ben Goetter
In reply to this post by Jakub-8
Another approach:

     Transcript show: 'Price is: ';
                show: (pomPrice printShowingDecimalPlaces: 2);
                cr.

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners