Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Math helpers in $util.math

Focus mode
Math helpers in $util.math - AWS AppSync GraphQL
Note

We now primarily support the APPSYNC_JS runtime and its documentation. Please consider using the APPSYNC_JS runtime and its guides here.

$util.math contains methods to help with common Math operations.

$util.math utils list

$util.math.roundNum(Double) : Integer

Takes a double and rounds it to the nearest integer.

$util.math.minVal(Double, Double) : Double

Takes two doubles and returns the minimum value between the two doubles.

$util.math.maxVal(Double, Double) : Double

Takes two doubles and returns the maximum value between the two doubles.

$util.math.randomDouble() : Double

Returns a random double between 0 and 1.

Important

This function shouldn't be used for anything that needs high entropy randomness (for example, cryptography).

$util.math.randomWithinRange(Integer, Integer) : Integer

Returns a random integer value within the specified range, with the first argument specifying the lower value of the range and the second argument specifying the upper value of the range.

Important

This function shouldn't be used for anything that needs high entropy randomness (for example, cryptography).

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.