Re: Identify if a scalar is int, double or text
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Sat, 12 May 2007 18:39:52 GMT
"K" == Klaus <klaus03@xxxxxxxxx> writes:
K> I want to stay with the standard built-in "int / double" arithmetic,
K> but I want additional control of the transition between the (as I see
K> it) 3 types of numerical values:
K> type 1. (int)
K> type 2. (double, with only integral values)
K> type 3. (double, with free decimal values)
K> This control should be implemented efficiently, hence my preference
K> for subroutines written in C.
you can force integer match with use integer. but the normal way to
manage money exactly has always been to use an integer for the lowest
denomination. this means for dollars you count integer cents. only when
you convert in/out for printing do you deal with the decimal point. this
way you get total control, speed, accuracy, and easy rounding with
int(). if you want more accuracy (.1 cents) just make that your count
size. and you can overflow to float as a large int (> 32 bits) and get
47 bits of int so there will never be a loss of digits until you get to
be richer than uncle bill.
and i agree with paul, needing to know so much detail is not
perlish. using ints for money is what you want to do and is easy in
perl.
uri
--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.
- Follow-Ups:
- Re: Identify if a scalar is int, double or text
- From: Klaus
- Re: Identify if a scalar is int, double or text
- References:
- Identify if a scalar is int, double or text
- From: Klaus
- Re: Identify if a scalar is int, double or text
- From: anno4000
- Re: Identify if a scalar is int, double or text
- From: Klaus
- Re: Identify if a scalar is int, double or text
- From: anno4000
- Re: Identify if a scalar is int, double or text
- From: Klaus
- Re: Identify if a scalar is int, double or text
- From: Dr.Ruud
- Re: Identify if a scalar is int, double or text
- From: Klaus
- Identify if a scalar is int, double or text
- Prev by Date: Perl Tutorial With Exercises
- Next by Date: FAQ 4.57 How do I look up a hash element by value?
- Previous by thread: Re: Identify if a scalar is int, double or text
- Next by thread: Re: Identify if a scalar is int, double or text
- Index(es):
Relevant Pages
|