Page 1 of 1 1
Topic Options
#146442 - 2005-08-25 02:59 PM KIX appears to be supressing decimal fractions ?
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
I want $l2 to be a decimal fraction but it is beng automatically rounded to an integer. I have tried formatting it as CDbl or FormatNumber to no avail !
How do I Dim $l2 to remain as a fraction ?

Little Example
Code:

for $x = 1 to 12
$year = 2000 + $x
$l1 =int($year/4)
$l2 =$year/4
? $l1 " ~ " $l2
if $l1 = $l2 ? "LEAPYEAR" endif
next
sleep 10



This fails every time in KIX as the decimal fractions
are supressed... How to Unsupress !

Top
#146443 - 2005-08-25 03:09 PM Re: KIX appears to be supressing decimal fractions ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
How about this:

Code:

for $x = 1 to 12
$year = 2000 + $x
if cdbl($year)/4 = $year/4
? "$year = LEAPYEAR"
endif
next



Point being - you got to get your your Double's happening as the very first part of the expression, in order for it to be treated (and tested) as floating point - in your example, the fractional part was being ignored.

Top
#146444 - 2005-08-25 03:14 PM Re: KIX appears to be supressing decimal fractions ?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Also be aware of your conditional comparisons when using an integer and a double.


if $year/4 = cdbl($year)/4

produces a different result from that of


if cdbl($year)/4 = $year/4

The double needs to be on the left side of the compare.

[edit]
Doh! Shawn I think already stated this...
[/edit]


Edited by Howard Bullock (2005-08-25 03:15 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#146445 - 2005-08-25 03:19 PM Re: KIX appears to be supressing decimal fractions ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
You weren't seeing things Hoby ... I went back and edited my post to provide more information.
Top
#146446 - 2005-08-25 03:59 PM Re: KIX appears to be supressing decimal fractions ?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and to golf a little:
if (0.+$year)/4 = $year/4

-1 stroke
_________________________
!

download KiXnet

Top
#146447 - 2005-08-25 05:39 PM Re: KIX appears to be supressing decimal fractions ?
MACE Offline
Starting to like KiXtart

Registered: 2004-09-07
Posts: 150
Loc: Manchester UK
Sweet !

Thanks all,

KIX certainly has some 'idiosyncrasies'

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 267 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.128 seconds in which 0.063 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org