com.jidesoft.converter.PercentConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jide-oss Show documentation
Show all versions of jide-oss Show documentation
JIDE Common Layer (Professional Swing Components)
/*
* @(#)PercentConverter.java 4/10/2007
*
* Copyright 2002 - 2007 JIDE Software Inc. All rights reserved.
*/
package com.jidesoft.converter;
import java.text.NumberFormat;
import java.util.Locale;
/**
* Converter which converts percentage to String and converts it back.
*/
public class PercentConverter extends NumberFormatConverter {
public static ConverterContext CONTEXT = new ConverterContext("Percent");
public PercentConverter() {
this(NumberFormat.getPercentInstance(Locale.getDefault()));
}
public PercentConverter(NumberFormat format) {
super(format);
}
@Override
public Object fromString(String string, ConverterContext context) {
Object o = super.fromString(string, context);
if (string != null && !string.trim().endsWith("%") && o instanceof Number && ((Number) o).doubleValue() > 1) {
o = ((Number) o).doubleValue() / 100;
}
return o;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy