SRL Archive - Help

Decimal Numbers ?


caused

2012-06-07 17:55:13

program new;
var
test:double;
begin
test := 15/10;
writeln( test );
end.

Why does that print 1 ?

cant simba use decimal numbers :x ?

Runaway

2012-06-07 17:57:16

Try extended?

caused

2012-06-07 17:57:53

same result.

Though double should work :x ..

Runaway

2012-06-07 18:00:52

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

2012-06-07 18:00:55

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 ?

Gu3st...

2012-06-07 18:04:09

Yes:

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

Nebula

2012-06-07 18:04:12

From: caused
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

2012-06-07 18:06:04

From: caused
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

2012-06-07 18:07:12

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

2012-06-07 18:49:30

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)