Hello!

I have been successful in creating a routine that returns a rounded number that pleases me, but the problem is that it only returns a string. Even though it is submitted as a real, I have been unsuccessful in returning it in the same type. Does anyone have an idea?

Here is the fully functional routine by the way:

```
on roundThisNumber_toThisDecimalPlaces_withThisRoundingMethod_(number_to_round, decimal_places, rounding_method)
(*
1 = NSNumberFormatterRoundCeiling = Round up to next larger number with the proper number of digits after the decimal separator.
2 = NSNumberFormatterRoundFloor = Round down to next smaller number with the proper number of digits after the decimal separator.
3 = NSNumberFormatterRoundDown = Round down to next smaller number with the proper number of digits after the decimal separator.
4 = NSNumberFormatterRoundUp = Round the last digit, when followed by a 5, toward an even digit (.25 -> .2, .35 -> .4)
5 = NSNumberFormatterRoundHalfEven = Round up to next larger number with the proper number of digits after the decimal separator.
6 = NSNumberFormatterRoundHalfDown = Round down when a 5 follows putative last digit.
7 = NSNumberFormatterRoundHalfUp = Round up when a 5 follows putative last digit.
*)
set roundingMethods to {¬
current application's NSNumberFormatterRoundCeiling, ¬
current application's NSNumberFormatterRoundFloor, ¬
current application's NSNumberFormatterRoundDown, ¬
current application's NSNumberFormatterRoundUp, ¬
current application's NSNumberFormatterRoundHalfEven, ¬
current application's NSNumberFormatterRoundHalfDown, ¬
current application's NSNumberFormatterRoundHalfUp}
set theRoundingFormat to "0.##" as string --default decimal places format
if rounding_method < 1 and rounding_method > 7 then set rounding_method to 7 --make sure we have a valid default rounding method
if (decimal_places as integer) = 0 then
set theRoundingFormat to "0" as string
else if (decimal_places as integer) > 0 then
set theRoundingFormat to "0." as string
repeat with myCount from 1 to (decimal_places as integer)
--set theFormat to theFormat's stringByAppendingString_("#")
set theRoundingFormat to (theRoundingFormat & "#") as string
end repeat
end if
set number_formatter to current application's NSNumberFormatter's alloc()'s init()
tell number_formatter
setFormat_(theRoundingFormat)
setRoundingMode_(item rounding_method of roundingMethods)
set theRoundedValueAsString to stringFromNumber_(number_to_round)
end tell
return (theRoundedValueAsString) as string
end roundThisNumber_toThisDecimalPlaces_withThisRoundingMethod_
```

and you call it like this:

```
my roundThisNumber_toThisDecimalPlaces_withThisRoundingMethod_(123.456789, 2, 7)
```

returns : “123.46”

Browser: Safari 531.22.7

Operating System: Mac OS X (10.6)