JScript - getting integer part of decimal

parseInt(x) works but
round(x) does not (it passes the parser but crashes the program)

There is a slight difference between the two, parseInt will basically truncate and give the integer part whereas round will round the integer to the nearest integer.

I’m surprised if round crashes, since it’s part of JScript rather than Opus.

Can you provide some minimal code that shows the problem?

Me too, it's in many scripts and has never crashed.

We are talking about Math.round(), right?

tried round(x) and math.round(x) but not Math.round(x) many thanks @lxp and happy new year all :slight_smile:

When you say round crashed, do you mean the script failed with an error message (because the function isn't defined), or did the whole program actually crash?

no error message, the dialog window flashed white and dissapeared.

A dialog closing isn’t the same as a crash. :slight_smile:

We still have no example code to reproduce any issue.

it's a crash. Not a Directory Opus crash, a programmitical crash of the script.

For instance (this is not the only way of crashing a script like this) change the Math.round to math.round and it will crash

		if (iconDPI != 100 && iconDPI >= DPI_LOWER && iconDPI <= DPI_UPPER) 
		{
			dialog.Control("static24").label = DOpus.DPI.dpi + " (" + Math.round((DOpus.DPI.dpi * iconDPI) / 100) + ")";
		    dialog.Control("static14").label = FOLDER_DETAILS[0][0][1] + " px" + "  (" + Math.round((FOLDER_DETAILS[0][0][1] / iconDPI) * 100) + "px)";
		    dialog.Control("static15").label = FOLDER_DETAILS[1][0][1] + " px" + "  (" + Math.round((FOLDER_DETAILS[1][0][1] / iconDPI) * 100) + "px)";
		}

if logging is on then this message is displayed
image

Be careful with what you classify as crash - you might get asked to send in the crash logs :wink:

2 Likes

That's an error, not a crash.