is there a function to check if a number is whole or not? i tried using
but that doesnt work cuz i guess mod only works with integers =/SCAR Code:function Iswhole(i: extended): Boolean;
begin
Result:= ((i mod 1) = 0);
end;
is there a function to check if a number is whole or not? i tried using
but that doesnt work cuz i guess mod only works with integers =/SCAR Code:function Iswhole(i: extended): Boolean;
begin
Result:= ((i mod 1) = 0);
end;
Well... I have here a func to make a # whole. Here it is:
SCAR Code:Function MakeWhole(number:Extended):Integer;
Var
i:String;
Begin
i:=FloatToStr(Trunc(number));//make trunc to round to round the # rather than truncate it.
Result:=StrToInt(i);
End;
Begin //how to test
Writeln(IntToStr(MakeWhole(7.3)));
End.
Leme try to get a IsWhole func, one sec.
EDIT: Got one!!!
SCAR Code:Function IsWhole(number:Extended):Boolean;
Var
q:Extended;
Begin
Result:=False;
q:=Trunc(number);
If (q=number) Then
Begin
Result:=True;
Exit;
End;
End;
Begin //how to test
Writeln('Is 7.4 whole? ' +BoolToStr(IsWhole(7.4)));
Writeln('Is 7 whole? ' +BoolToStr(IsWhole(7)));
End.
--------------------------------------------------------- ![]()
Pm me if you need any math functions made. Me = l0ving t3h mathz
--------------------------------------------------------- ![]()
woot thanks haha thats a nice way to see if its whole..round it down then see if it equals original number =) i just learned what trunc does. that is what it does right?
Yeah, trunc just slices off the decimal parts. (castrates a float lmao)
--------------------------------------------------------- ![]()
Pm me if you need any math functions made. Me = l0ving t3h mathz
--------------------------------------------------------- ![]()



Shorter:
Sorry, couldn't help myselfSCAR Code:function IsWhole(e: Extended): Boolean;
begin
Result:= StrToFloat(IntToStr(Trunc(e))) = e;
end;![]()
DAMN YOU TO HELL BULZEYE!!!!
I'm jk, nice consolidation.
--------------------------------------------------------- ![]()
Pm me if you need any math functions made. Me = l0ving t3h mathz
--------------------------------------------------------- ![]()
No strings attached.SCAR Code:function IsWhole(e: Extended): Boolean;
begin
Result:= 1.0*Trunc(e) = e;
end;
There are currently 1 users browsing this thread. (0 members and 1 guests)