Here you can find the source of formatVolume(Locale locale, String stringToFormat)
Parameter | Description |
---|---|
locale | Locale |
stringToFormat | String to format |
public static String formatVolume(Locale locale, String stringToFormat)
//package com.java2s; /*/*ww w . j a va2s . c om*/ * (C) Copyright Itude Mobile B.V., The Netherlands * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; public class Main { /** * Format {@link String} as a Volume * * WARNING: Only use this method to present data to the screen * * @param locale {@link Locale} * @param stringToFormat {@link String} to format * @return a string formatted as a volume with group separators (eg, 131.224.000) assuming the receiver is an int string read from XML */ public static String formatVolume(Locale locale, String stringToFormat) { if (stringToFormat == null || stringToFormat.length() == 0) { return null; } String result = null; DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalFormatSymbols(new DecimalFormatSymbols(locale)); formatter.setGroupingUsed(true); formatter.setGroupingSize(3); formatter.setMaximumFractionDigits(0); result = formatter.format(Double.parseDouble(stringToFormat)); return result; } }