Formatting numbers
Calculations will produce results with all decimal places shown without any formatting of the numbers which may not be desireable when displaying the results within orgvue
The method format()
will enable the number to be formated as desired whilst join()
allows the amalgamation of two or more elements so making it possible to add symbols to numbers e.g.%
or $
etc
Note using format()
or join()
will convert the number to string
Format
To convert the format of “Current salary” to "000,000.00"
Use format()
and put the desired form into the () within double quotes
node.currentsalary.format("0.00");
node.currentsalary
defines the collection you want to manipulate, here the current salary for a selected node.- The format method
.format("0.0")
puts the number into the desired form that you specify so thatnode.currentsalary.format("0.00")
will return 122,473.00 as specified in the problem above.
Join
join()
can be used to amalgamate two or more elements into a single string
Calculate Bonus as a percentage of Current Salary rounded to 1 decimal place with % symbol
Calculating the expression with rounding to the required places and then using the .join("")
function to add the %
symbol to the displayed result
[node.math("CurrentBonus/CurrentSalary*100")
.round(1),"%"].join("")
node.math("CurrentBonus/CurrentSalary*100")
calculates the Bonus as a percent of salary e.g. 18.501220677210487- Adding
.round(1)
then rounds the result to one decimal place e.g. 18.5 - Placing
[ ]
around the expression along with,"%"
inside those brackets and the.join("")
method afterwards gives the full expression to produce the output 18.5%