本文整理汇总了Java中com.ibm.icu.text.DecimalFormat类的典型用法代码示例。如果您正苦于以下问题:Java DecimalFormat类的具体用法?Java DecimalFormat怎么用?Java DecimalFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DecimalFormat类属于com.ibm.icu.text包,在下文中一共展示了DecimalFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: style
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
@Override
public PatternNode style(java.lang.String argumentName) {
Function<Locale, NumberFormat> formatFactory = Opt(() -> {
Str(",");
whiteSpace();
Function<Locale, NumberFormat> result = this
.<Function<Locale, NumberFormat>> FirstOf(() -> {
Str("integer");
return l -> NumberFormat.getIntegerInstance(l);
} , () -> {
Str("currency");
return l -> NumberFormat.getCurrencyInstance(l);
} , () -> {
Str("percent");
return l -> NumberFormat.getPercentInstance(l);
} , () -> {
String pattern = subFormatPattern();
return l -> new DecimalFormat(pattern,
DecimalFormatSymbols.getInstance(l));
});
whiteSpace();
return result;
}).orElse(l -> NumberFormat.getInstance(l));
return new FormatNode(argumentName, formatFactory);
}
示例2: normalizeDouble
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
public static Number normalizeDouble( Double dValue, String pattern )
{
Number value = null;
if ( pattern != null && pattern.trim( ).length( ) > 0 )
{
NumberFormat df = new DecimalFormat( pattern );
String sValue = df.format( dValue );
try
{
value = df.parse( sValue );
}
catch ( ParseException e )
{
logger.log( e );;
}
}
else
{
value = normalizeDouble( dValue );
}
return value;
}
示例3: getDecimalFormat
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
DecimalFormat getDecimalFormat()
{
if ( this.si.fs == null ) // CREATE IF FORMAT SPECIFIER IS UNDEFINED
{
if ( !as.isBigNumber( ) )
{
this.df = as.computeDecimalFormat( dAxisValue, dAxisStep );
}
else
{
this.df = as.computeDecimalFormat( bdAxisValue.multiply( as.getBigNumberDivisor( ),
NumberUtil.DEFAULT_MATHCONTEXT ), bdStep);
}
}
return this.df;
}
示例4: format
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
public String format( Object obj )
{
String str = ""; //$NON-NLS-1$
if ( obj != null )
{
if ( obj instanceof Number )
{
// TODO: use format cache to improve performance
double d = ( (Number) obj ).doubleValue( );
String sPattern = ValueFormatter.getNumericPattern( d );
DecimalFormat df = new DecimalFormat( sPattern );
str = df.format( d );
}
else
{
str = obj.toString( );
}
}
return str;
}
示例5: format
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
public String format( Number number, ULocale lo )
{
Number n = NumberUtil.transformNumber( number );
if ( n instanceof Double )
{
return format( ( (Double) n ).doubleValue( ), lo );
}
// Format big decimal
BigDecimal bdNum = (BigDecimal) n;
final DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance( lo );
String vPattern = NumberUtil.adjustBigNumberFormatPattern( getPattern( ) );
if ( vPattern.indexOf( 'E' ) < 0 )
{
vPattern = vPattern + NumberUtil.BIG_DECIMAL_FORMAT_SUFFIX;
}
df.applyPattern( vPattern );
return isSetMultiplier( ) ? df.format( bdNum.multiply( BigDecimal.valueOf( getMultiplier( ) ),
NumberUtil.DEFAULT_MATHCONTEXT ) )
: df.format( bdNum );
}
示例6: format
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
public String format( double dValue, ULocale lo )
{
final DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance( lo );
if ( isSetFractionDigits( ) )
{
df.setMinimumFractionDigits( getFractionDigits( ) );
df.setMaximumFractionDigits( getFractionDigits( ) );
}
df.applyLocalizedPattern( df.toLocalizedPattern( ) );
final StringBuffer sb = new StringBuffer( );
if ( getPrefix( ) != null )
{
sb.append( getPrefix( ) );
}
sb.append( isSetMultiplier( ) ? df.format( dValue * getMultiplier( ) )
: df.format( dValue ) );
if ( getSuffix( ) != null )
{
sb.append( getSuffix( ) );
}
return sb.toString( );
}
示例7: createNumberFormat
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
private NumberFormat createNumberFormat() {
ULocale locale = ULocale.forLanguageTag(this.locale);
locale = locale.setKeywordValue("numbers", "latn");
DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale, NumberFormat.NUMBERSTYLE);
if (minimumSignificantDigits != 0 && maximumSignificantDigits != 0) {
numberFormat.setSignificantDigitsUsed(true);
numberFormat.setMinimumSignificantDigits(minimumSignificantDigits);
numberFormat.setMaximumSignificantDigits(maximumSignificantDigits);
} else {
numberFormat.setSignificantDigitsUsed(false);
numberFormat.setMinimumIntegerDigits(minimumIntegerDigits);
numberFormat.setMinimumFractionDigits(minimumFractionDigits);
numberFormat.setMaximumFractionDigits(maximumFractionDigits);
}
// as required by ToRawPrecision/ToRawFixed
numberFormat.setRoundingMode(BigDecimal.ROUND_HALF_UP);
return numberFormat;
}
示例8: toFixedDecimal
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
@SuppressWarnings("deprecation")
com.ibm.icu.text.PluralRules.FixedDecimal toFixedDecimal(double n) {
NumberFormat nf = getNumberFormat();
StringBuffer sb = new StringBuffer();
FieldPosition fp = new FieldPosition(DecimalFormat.FRACTION_FIELD);
nf.format(n, sb, fp);
int v = fp.getEndIndex() - fp.getBeginIndex();
long f = 0;
if (v > 0) {
ParsePosition pp = new ParsePosition(fp.getBeginIndex());
f = nf.parse(sb.toString(), pp).longValue();
}
return new com.ibm.icu.text.PluralRules.FixedDecimal(n, v, f);
}
示例9: createNumberFormat
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
private static NumberFormat createNumberFormat(final Element element) {
Element numberFormatElement = element.getChild(XMLTags.NUMBER);
String pattern = numberFormatElement.getChildText(XMLTags.PATTERN);
Element localeElement = numberFormatElement.getChild(XMLTags.LOCALE);
String language = localeElement.getChildText(XMLTags.LANGUAGE);
String country = localeElement.getChildText(XMLTags.COUNTRY);
ULocale locale = new ULocale(language, country);
return new DecimalFormat(pattern, new DecimalFormatSymbols(locale));
}
示例10: createNumberFormat
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
private NumberFormat createNumberFormat() {
ULocale locale = ULocale.forLanguageTag(this.locale);
int choice;
if ("decimal".equals(style)) {
choice = NumberFormat.NUMBERSTYLE;
} else if ("percent".equals(style)) {
choice = NumberFormat.PERCENTSTYLE;
} else {
if ("code".equals(currencyDisplay)) {
choice = NumberFormat.ISOCURRENCYSTYLE;
} else if ("symbol".equals(currencyDisplay)) {
choice = NumberFormat.CURRENCYSTYLE;
} else {
choice = NumberFormat.PLURALCURRENCYSTYLE;
}
}
DecimalFormat numberFormat = (DecimalFormat) NumberFormat.getInstance(locale, choice);
if ("currency".equals(style)) {
numberFormat.setCurrency(Currency.getInstance(currency));
}
// numberingSystem is already handled in language-tag
// assert locale.getKeywordValue("numbers").equals(numberingSystem);
if (minimumSignificantDigits != 0 && maximumSignificantDigits != 0) {
numberFormat.setSignificantDigitsUsed(true);
numberFormat.setMinimumSignificantDigits(minimumSignificantDigits);
numberFormat.setMaximumSignificantDigits(maximumSignificantDigits);
} else {
numberFormat.setSignificantDigitsUsed(false);
numberFormat.setMinimumIntegerDigits(minimumIntegerDigits);
numberFormat.setMinimumFractionDigits(minimumFractionDigits);
numberFormat.setMaximumFractionDigits(maximumFractionDigits);
}
numberFormat.setGroupingUsed(useGrouping);
// as required by ToRawPrecision/ToRawFixed
// FIXME: ICU4J bug:
// new Intl.NumberFormat("en",{useGrouping:false}).format(111111111111111)
// returns "111111111111111.02"
numberFormat.setRoundingMode(BigDecimal.ROUND_HALF_UP);
return numberFormat;
}
示例11: sciToDollar
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
public static String sciToDollar(double valueToRound)
{
double roundedValue = Math.round(valueToRound);
DecimalFormat df = new DecimalFormat("#0");
NumberFormat formatter = NumberFormat.getCurrencyInstance();
df.format(roundedValue);
String retString = formatter.format(roundedValue);
return retString;
}
示例12: WebSearchResultPanel
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
public WebSearchResultPanel(String id, SolrDocument doc, final SearchResultsDataProvider dataProvider) {
super(id, doc, dataProvider);
String contentLength = (String) doc.getFieldValue("contentLength");
String type = (String) doc.getFieldValue("subType");
String contentLengthKBStr;
if (StringUtils.isNotBlank(contentLength)) {
long contentLengthBytes;
try {
contentLengthBytes = Long.valueOf(contentLength);
} catch (NumberFormatException e) {
contentLengthBytes = -1;
}
double contentLengthKB = (double) contentLengthBytes / 1000;
DecimalFormat contentLengthKBFormatter = new DecimalFormat();
contentLengthKBFormatter.setMinimumFractionDigits(0);
contentLengthKBFormatter.setMaximumFractionDigits(0);
contentLengthKBStr = contentLengthKBFormatter.format(contentLengthKB);
if ("0".equals(contentLengthKBStr)) {
contentLengthKBStr = null;
}
} else {
contentLengthKBStr = null;
}
add(new Label("contentLength", contentLengthKBStr + " KB").setVisible(contentLengthKBStr != null));
add(new Label("type", type).setVisible(StringUtils.isNotBlank(type)));
}
示例13: IntelliGIDSearchResultPanel
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
public IntelliGIDSearchResultPanel(String id, SolrDocument doc, final SearchResultsDataProvider dataProvider) {
super(id, doc, dataProvider);
String contentLength = (String) doc.getFieldValue("contentLength");
String type = (String) doc.getFieldValue("subType");
String contentLengthKBStr;
if (StringUtils.isNotBlank(contentLength)) {
long contentLengthBytes;
try {
contentLengthBytes = Long.valueOf(contentLength);
} catch (NumberFormatException e) {
contentLengthBytes = -1;
}
double contentLengthKB = (double) contentLengthBytes / 1000;
DecimalFormat contentLengthKBFormatter = new DecimalFormat();
contentLengthKBFormatter.setMinimumFractionDigits(0);
contentLengthKBFormatter.setMaximumFractionDigits(0);
contentLengthKBStr = contentLengthKBFormatter.format(contentLengthKB);
if ("0".equals(contentLengthKBStr)) {
contentLengthKBStr = null;
}
} else {
contentLengthKBStr = null;
}
add(new Label("contentLength", contentLengthKBStr + " KB").setVisible(contentLengthKBStr != null));
add(new Label("type", type).setVisible(StringUtils.isNotBlank(type)));
}
示例14: espaSubprojects
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
public static void espaSubprojects() throws ParseException {
//services for each table
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
SubProjectsService sub = (SubProjectsService) ctx.getBean("subProjectsServiceImpl");
List<SubProjects> subProject = sub.getSubProjects();
//--------------RDF Model--------------//
Model model = ModelFactory.createDefaultModel();
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
InfModel infModel = ModelFactory.createInfModel(reasoner, model);
model.setNsPrefix("elod", OntologySpecification.elodPrefix);
model.setNsPrefix("gr", OntologySpecification.goodRelationsPrefix);
model.setNsPrefix("dcterms", OntologySpecification.dctermsPrefix);
//number format
DecimalFormat df = new DecimalFormat("0.00");
for (SubProjects subProject1 : subProject) {
Resource instanceCurrency = infModel.createResource("http://linkedeconomy.org/resource/Currency/EUR");
Resource instanceBudgetUps = infModel.createResource(OntologySpecification.instancePrefix
+ "UnitPriceSpecification/BudgetItem/" + subProject1.getOps() + "/" + subProject1.getId());
Resource instanceBudget = infModel.createResource(OntologySpecification.instancePrefix + "BudgetItem/" + subProject1.getOps() + "/" + subProject1.getId());
Resource instanceSubProject = infModel.createResource(OntologySpecification.instancePrefix + "Subproject/" + subProject1.getOps() + "/" + subProject1.getId());
Resource instanceProject = infModel.createResource(OntologySpecification.instancePrefix
+ "Subsidy/" + subProject1.getOps());
DateFormat dfDate = new SimpleDateFormat("dd/MM/yyyy");
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
java.util.Date stDateStarts;
java.util.Date stDateEnds;
stDateStarts = dfDate.parse(subProject1.getStart());
stDateEnds = dfDate.parse(subProject1.getFinish());
String startDate = df2.format(stDateStarts);
String endDate = df2.format(stDateEnds);
infModel.add(instanceProject, RDF.type, OntologySpecification.projectResource);
infModel.add(instanceBudgetUps, RDF.type, OntologySpecification.priceSpecificationResource);
infModel.add(instanceBudget, RDF.type, OntologySpecification.budgetResource);
infModel.add(instanceSubProject, RDF.type, OntologySpecification.subProjectResource);
instanceProject.addProperty(OntologySpecification.hasRelatedProject, instanceSubProject);
instanceSubProject.addProperty(OntologySpecification.hasRelatedBudgetItem, instanceBudget);
instanceBudget.addProperty(OntologySpecification.price, instanceBudgetUps);
instanceBudgetUps.addProperty(OntologySpecification.hasCurrencyValue, df.format(subProject1.getBudget()), XSDDatatype.XSDfloat);
instanceBudgetUps.addProperty(OntologySpecification.valueAddedTaxIncluded, "true", XSDDatatype.XSDboolean);
instanceBudgetUps.addProperty(OntologySpecification.hasCurrency, instanceCurrency);
instanceSubProject.addProperty(OntologySpecification.startDate, startDate, XSDDatatype.XSDdateTime);
instanceSubProject.addProperty(OntologySpecification.endDate, endDate, XSDDatatype.XSDdateTime);
instanceSubProject.addProperty(OntologySpecification.title, String.valueOf(subProject1.getTitle()), "el");
}
try {
FileOutputStream fout = new FileOutputStream(
"/Users/giovaf/Documents/yds_pilot1/espa_tests/22-02-2016_ouput/subProjectEspa.rdf");
model.write(fout);
} catch (IOException e) {
System.out.println("Exception caught" + e.getMessage());
}
}
示例15: exportRfd
import com.ibm.icu.text.DecimalFormat; //导入依赖的package包/类
/**
*
* Implementation Of Subproject Service layer
* and transformation of Database data to RDF
*
* @throws java.text.ParseException
* @throws java.io.UnsupportedEncodingException
* @throws java.io.FileNotFoundException
*/
public static void exportRfd() throws ParseException, UnsupportedEncodingException, FileNotFoundException, IOException {
//services for each table
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
SubProjectsService sub = (SubProjectsService) ctx.getBean("subProjectsServiceImpl");
List<SubprojectsProjects> subProject = sub.getInfoSubproject();
//--------------RDF Model--------------//
Model model = ModelFactory.createDefaultModel();
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
InfModel infModel = ModelFactory.createInfModel(reasoner, model);
model.setNsPrefix("elod", OntologySpecification.elodPrefix);
model.setNsPrefix("gr", OntologySpecification.goodRelationsPrefix);
model.setNsPrefix("dcterms", OntologySpecification.dctermsPrefix);
//number format
DecimalFormat df = new DecimalFormat("0.00");
for (SubprojectsProjects subProject1 : subProject) {
Resource instanceCurrency = infModel.createResource("http://linkedeconomy.org/resource/Currency/EUR");
Resource instanceUps = infModel.createResource(OntologySpecification.instancePrefix
+ "UnitPriceSpecification/" + subProject1.getOps() + "/" + subProject1.getSubprojectId());
Resource instanceBudget = infModel.createResource(OntologySpecification.instancePrefix + "BudgetItem/" + subProject1.getOps() + "/" + subProject1.getSubprojectId());
Resource instanceSubProject = infModel.createResource(OntologySpecification.instancePrefix + "Contract/" + subProject1.getOps() + "/" + subProject1.getSubprojectId());
Resource instanceProject = infModel.createResource(OntologySpecification.instancePrefix
+ "PublicWork/" + subProject1.getOps());
infModel.add(instanceUps, RDF.type, OntologySpecification.priceSpecificationResource);
infModel.add(instanceBudget, RDF.type, OntologySpecification.budgetResource);
infModel.add(instanceSubProject, RDF.type, OntologySpecification.contractResource);
instanceProject.addProperty(OntologySpecification.hasRelatedContract, instanceSubProject);
instanceSubProject.addProperty(OntologySpecification.price, instanceUps);
instanceUps.addProperty(OntologySpecification.hasCurrencyValue, df.format(subProject1.getBudget()), XSDDatatype.XSDfloat);
instanceUps.addProperty(OntologySpecification.valueAddedTaxIncluded, "true", XSDDatatype.XSDboolean);
instanceUps.addProperty(OntologySpecification.hasCurrency, instanceCurrency);
if (subProject1.getStart() != null) {
instanceSubProject.addProperty(OntologySpecification.pcStartDate, subProject1.getStart().replace("/", "-"), XSDDatatype.XSDdate);
}
if (subProject1.getFinish() != null) {
instanceSubProject.addProperty(OntologySpecification.actualEndDate, subProject1.getFinish().replace("/", "-"), XSDDatatype.XSDdate);
}
instanceSubProject.addProperty(OntologySpecification.title, String.valueOf(subProject1.getTitle()), "el");
}
try {
FileOutputStream fout = new FileOutputStream(
CommonVariables.serverPath + "subProjectEspa_"+ CommonVariables.currentDate + ".rdf");
model.write(fout);
fout.close();
} catch (IOException e) {
System.out.println("Exception caught" + e.getMessage());
}
}