 let SIGNIFICAND_DIGIT = 7
 let COMMA_SEPARATOR = ","
 
-func _calculatorString(num: Double) -> String
+///
+/// add either expontent or readable-commas to numString as follows:
+///
+/// - "123" -> "123" (no change)
+/// - "12345.6700" -> "12,345.67" (rtrims=true) or "12,345.6700" (rtrims=false)
+/// - "123456789" -> "1.234567e+8"
+/// - inf -> "inf"
+/// - NaN -> "nan"
+///
+func _calculatorString(numString: NSString, rtrims rtrimsSuffixedPointAndZeros: Bool = true) -> String
 {
+    let num = numString.doubleValue
+    
     // return "inf" or "nan" if needed
     if !num.isFinite { return "\(num)" }
     

    }
    // add commas for integer-part
    else {
        
        string = NSString(format: "%0.\(DECIMAL_PRECISION)f", num) // NOTE: `%f` will never print exponent
        
        // split by `.Point`
        let splittedStrings = string.componentsSeparatedByString(Calculator.Key.Point.rawValue)
        if let integerString = splittedStrings.first as? String {
            
            var integerCharacters = Array(integerString)
            
            // insert commas
            for var i = countElements(integerCharacters) - 3; i > 0; i -= 3 {
                integerCharacters.insert(Character(COMMA_SEPARATOR), atIndex: i)
            }
            
            string = String(integerCharacters)
            
            if splittedStrings.count == 2 {
                // append `.Point` & decimal-part
                string = string + (Calculator.Key.Point.rawValue as String) + (splittedStrings.last! as String)
            }
        }
        
        var nonNumberCount = 0
        for char in string as String {
            if char == Character(COMMA_SEPARATOR) || char == Character(Calculator.Key.Point.rawValue) {
                nonNumberCount++
            }
        }
        
        // limit to MAX_DIGIT_FOR_NONEXPONENT considering non-number characters
        if string.length > MAX_DIGIT_FOR_NONEXPONENT + nonNumberCount {
            string = string.substringToIndex(MAX_DIGIT_FOR_NONEXPONENT + nonNumberCount)
        }
        
        string = _rtrimFloatString(string)
    }
    
    return string
}

/// e.g. `123.000` -> `123`
func _rtrimFloatString(var string: NSString) -> String
{
    // trim floating zeros, e.g. `123.000` -> `123.`

{
    var calculatorString: String
    {
        let numString = NSString(format: "%0.\(DECIMAL_PRECISION)f", self) // NOTE: `%f` will never print exponent
        return _calculatorString(numString, rtrims: true)
    }
}

