v and it will return either:
vis one or more cents/pennies/whatever away from a round dollar/pound/whatever: a String that is
vrounded to 2 decimal places.
vas a Number rounded to the nearest dollar/pound/whatever.
So, for example:
roundToCashString(23); // returns 23 roundToCashString(23.002); // returns 23 roundToCashString(23.005); // returns 23.01 (as a String) roundToCashString(23.56789); // returns 23.57 (as a String)
The function can therefore return either a Number or a String. I didn’t add a line to convert a return Number to a String because it was completely unnecessary for my purposes, but it would be easy enough by changing line 5 to
integer + "";
It goes without saying but use as you wish!