Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Rounding to nearest multiple of 0.5 keeping 0.25 as the deciding factor

Avatar

Level 1

Dear All,

How could I round amounts as illustrated by the following examples in Adobe Livecycle Designer?

8.06 = 8.00, 8.26 = 8.50, 8.74 = 8.50, 8.76 = 9.00

Thanks,

Sandeep

1 Reply

Avatar

Level 10

Hi Sandeep,

I don't think there's any trick to doing this, you just have to test and adjust the values yourself, something like;

app.alert(roundToNearestHalf(8.06));

app.alert(roundToNearestHalf(8.26));

app.alert(roundToNearestHalf(8.74));

app.alert(roundToNearestHalf(8.76));

function roundToNearestHalf(number)

{

    var result = Math.floor(number);

    var fraction = number - result;

    if (fraction >= 0.75)

    {

        result++;

    }

    else

    {

        if (fraction > 0.25)

        {

            result += 0.5;

        }

    }

    return result;

}

Regards

Bruce