Log in

View Full Version : Decimal Numbers ?



caused
06-07-2012, 09:55 PM
program new;
var
test:double;
begin
test := 15/10;
writeln( test );
end.

Why does that print 1 ?

cant simba use decimal numbers :x ?

Runaway
06-07-2012, 09:57 PM
Try extended?

caused
06-07-2012, 09:57 PM
same result.

Though double should work :x ..

Runaway
06-07-2012, 10:00 PM
Interesting... it works with multiplication:


var
a: extended;
begin
a := 0.1 * 5;
writeln(a);
end.



Compiled successfully in 858 ms.
0.5
Successfully executed.

caused
06-07-2012, 10:00 PM
If I do it like this:

program new;
var
test:extended;
begin
test := 15.0/10.0;
writeln( test );
end.

it works.

Isnt there another solution though : X ?

Zyt3x
06-07-2012, 10:04 PM
Yes:

E := (Int * 1.0) / (Int2 * 1.0);

Nebula
06-07-2012, 10:04 PM
If I do it like this:

program new;
var
test:extended;
begin
test := 15.0/10.0;
writeln( test );
end.

it works.

Isnt there another solution though : X ?

this would work too..

program new;
begin
writeln( 15.0/10.0 );
end.

weequ
06-07-2012, 10:06 PM
If I do it like this:

program new;
var
test:extended;
begin
test := 15.0/10.0;
writeln( test );
end.

it works.

Isnt there another solution though : X ?
test := ((extended)15)/((extended)10);

or something similar should work too.

Edit: Might have been extended(15)/extended(10);

Runaway
06-07-2012, 10:07 PM
Yeah, one of them has to be a decimal itself (extended):


var
a, b, c: extended;
begin
a := 15;
b := 10;
c := a div b;
writeln(c);
end.



Compiled successfully in 842 ms.
1.5
Successfully executed.

masterBB
06-07-2012, 10:49 PM
Pascalscript will take the most precise number of an equation and uses that to decide if it uses integer division or extended/real division.

1.0 / 3 = 0.33333... and 1 / 3 = 0

Lape always uses a precise division.

1.0 / 3 = 0.33333... and 1 / 3 = 0.33333...

If you want to use integer division in lape use div.

1.0 div 3 = 0 and 1 div 3 = 0

edit:
quite a popular thread this is:
Currently Active Users Viewing This Thread: 17 (2 members and 15 guests)

edit:
It's popularity knows no limits:
Currently Active Users Viewing This Thread: 21 (1 members and 20 guests)