Inherits from NSObject
Declared in JOECurrencyUtil.h

Overview

This is a collection of utility methods for dealing with currency. It allows you to handle input into a textfield or similiar UI, formatting the number correctly.

Tasks

Decimal From Currency String

Currency String From Decimal Number

Unformatting Text

  • + cleanCurrencyString:

    This method cleans a NSString representing currency. It takes an inverted decimalDigitCharacterSet to remove currency symbols, commas, and decimals.

  • + removableCharacterSet

    Returns a character set that includes everything but decimal digits and the current locale’s decimal seperator.

Class Methods

cleanCurrencyString:

This method cleans a NSString representing currency. It takes an inverted decimalDigitCharacterSet to remove currency symbols, commas, and decimals.

+ (NSString *)cleanCurrencyString:(NSString *)string

Parameters

string

The string to be cleaned.

Return Value

The resulting digit only string.

Declared In

JOECurrencyUtil.h

decimalNumberFromCurrencyString:

Method converts a string formatted as currency to a decimal number object with a scale of 2.

+ (NSDecimalNumber *)decimalNumberFromCurrencyString:(NSString *)string

Parameters

string

NSString argument to be converted to a decimal number

Return Value

The resulting NSDecimalNumber object.

Discussion

@b Example: @"$10,545.32" -> 10545.32

Declared In

JOECurrencyUtil.h

decimalNumberFromCurrencyString:scale:

Method converts a string formatted as currency to a decimal number object with a given scale argument.

+ (NSDecimalNumber *)decimalNumberFromCurrencyString:(NSString *)string scale:(short)scale

Parameters

string

NSString argument to be converted to a decimal number

scale

The number of digits a rounded value should have after its decimal point.

Return Value

The resulting NSDecimalNumber object.

Discussion

@b Example: Given scale:4, @"$0.0045" -> 0.0045

Declared In

JOECurrencyUtil.h

removableCharacterSet

Returns a character set that includes everything but decimal digits and the current locale’s decimal seperator.

+ (NSCharacterSet *)removableCharacterSet

Return Value

Returns a character set.

Declared In

JOECurrencyUtil.h

stringFromDecimalNumber:

Method converts a decimal number to a string with 2 digits after its decimal point.

+ (NSString *)stringFromDecimalNumber:(NSDecimalNumber *)number

Parameters

number

The NSDecimalNumber to be converted to a NSString

Return Value

The resulting NSString.

Declared In

JOECurrencyUtil.h

stringFromDecimalNumber:scale:

Method converts a decimal number to a string with a given scale.

+ (NSString *)stringFromDecimalNumber:(NSDecimalNumber *)number scale:(short)scale

Parameters

number

The NSDecimalNumber to be converted to a NSString

scale

The number of digits a rounded value should have after its decimal point.

Return Value

The resulting NSString.

Declared In

JOECurrencyUtil.h