Search in sources :

Example 1 with NSNumberFormatter

use of com.webobjects.foundation.NSNumberFormatter in project wonder-slim by undur.

the class AjaxSlider method takeValuesFromRequest.

@Override
public void takeValuesFromRequest(WORequest worequest, WOContext wocontext) {
    String format = null;
    try {
        format = (String) valueForBinding("numberformat", "0");
        Number num = worequest.numericFormValueForKey(wocontext.elementID(), new NSNumberFormatter(format));
        if (num != null) {
            setValueForBinding(num, "value");
        }
    } catch (NumberFormatException ex) {
        log.error("Could not format value with pattern '{}'.", format, ex);
    }
    super.takeValuesFromRequest(worequest, wocontext);
}
Also used : NSNumberFormatter(com.webobjects.foundation.NSNumberFormatter)

Example 2 with NSNumberFormatter

use of com.webobjects.foundation.NSNumberFormatter in project wonder-slim by undur.

the class ERXNumberFormatter method numberFormatterForPattern.

/**
 * Returns a shared instance for the specified pattern.
 * @return shared instance of formatter
 */
public static NSNumberFormatter numberFormatterForPattern(String pattern) {
    NSNumberFormatter formatter;
    if (ERXLocalizer.useLocalizedFormatters()) {
        ERXLocalizer localizer = ERXLocalizer.currentLocalizer();
        formatter = (NSNumberFormatter) localizer.localizedNumberFormatForKey(pattern);
    } else {
        formatter = _repository.get(pattern);
        if (formatter == null) {
            formatter = new ERXNumberFormatter(pattern);
            _repository.put(pattern, formatter);
        }
    }
    return formatter;
}
Also used : NSNumberFormatter(com.webobjects.foundation.NSNumberFormatter) ERXLocalizer(er.extensions.localization.ERXLocalizer)

Example 3 with NSNumberFormatter

use of com.webobjects.foundation.NSNumberFormatter in project wonder-slim by undur.

the class ERXLocalizer method localizedNumberFormatForKey.

/**
 * Returns a localized number formatter for the given key. Also, can localize units to, just define in your
 * Localizable.strings a suitable key, with the appropriate pattern.
 *
 * @return the formatter object
 */
public Format localizedNumberFormatForKey(String formatString) {
    formatString = formatString == null ? "#,##0.00;-(#,##0.00)" : formatString;
    formatString = localizedStringForKeyWithDefault(formatString);
    Format result = _numberFormatters.get(formatString);
    if (result == null) {
        Locale current = locale();
        NSNumberFormatter formatter = new ERXNumberFormatter();
        formatter.setLocale(current);
        formatter.setLocalizesPattern(true);
        formatter.setPattern(formatString);
        result = formatter;
        _numberFormatters.put(formatString, result);
    }
    return result;
}
Also used : Locale(java.util.Locale) Format(java.text.Format) NSNumberFormatter(com.webobjects.foundation.NSNumberFormatter) ERXNumberFormatter(er.extensions.formatters.ERXNumberFormatter)

Aggregations

NSNumberFormatter (com.webobjects.foundation.NSNumberFormatter)3 ERXNumberFormatter (er.extensions.formatters.ERXNumberFormatter)1 ERXLocalizer (er.extensions.localization.ERXLocalizer)1 Format (java.text.Format)1 Locale (java.util.Locale)1