Expand my Community achievements bar.

SOLVED

Rounding up to nearest whole number question

Avatar

Level 3

I have a calculation script that sometimes returns a decimal result. How would I create a script that would round that decimal up to the next whole number? Anyone have any idea's?

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

You can use the Ceil FormCalc function. For example,

// form1.page1.nf::exit - (FormCalc, client)


$.rawValue = Ceil(nf)

Steve

View solution in original post

4 Replies

Avatar

Correct answer by
Former Community Member

You can use the Ceil FormCalc function. For example,

// form1.page1.nf::exit - (FormCalc, client)


$.rawValue = Ceil(nf)

Steve

Avatar

Level 3

okay, I am not very good with this. That command is new to me. Where would I place that script if I already have a javascript script in the calculate event of that numeric field I am trying to get rounded up?

I basically have the javascript code in the numeric fields calculate event set to

this.rawValue = subform1.numericField1.rawValue;

I tried putting your script on the change event hoping I could use formCalc there but get a error when testing saying Ceil is not defined. Thanks

Avatar

Level 3

Okay nevermind.... I got it. I just changed the data format to integer in the binding tab of the Numeric Field and it worked. (Almost) it just rounds down to the lowest whole number. But Thats okay with me. Thanks

Avatar

Level 1

Can you create a script where you ONLY round up and not down?

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----