Page 1 of 1

Zero as a function parameter

Posted: Sun Jan 29, 2023 2:53 am
by matty47
I have the following function

Code: Select all

/*rounds a number n, (up/down) Or To a number of places d */
Function Round2(n,d)
	If d<>0 
		Return( Floor((n*(10^d)+0.5))/(10^d))
		
	Else
		Return Floor(n+0.5)
	EndIf
	
EndFunction
And test this with

Code: Select all

NPrint (Round2(3.157,1))
WaitLeftMouse
End
Which works fine. If I make the second parameter 0 (zero) I get a "Not enough parameters" in the NPrint which I presume is coming from the Round2 function.
What have I missed?? Thanks

Re: Zero as a function parameter

Posted: Sun Jan 29, 2023 2:37 pm
by Flinx
You forgot the parentheses at the second Return(), so you got no return value.

Code: Select all

Return(Floor(n+0.5))

Re: Zero as a function parameter

Posted: Mon Jan 30, 2023 12:18 am
by matty47
Thanks - Doh! another simple error on my side.