Here you can find the source of formatQuantity(Long quantity)
Parameter | Description |
---|---|
quantity | The quantity Long to be formatted |
public static String formatQuantity(Long quantity)
//package com.java2s; /*/*from ww w .j ava 2s . co m*/ * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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.math.BigDecimal; import java.text.DecimalFormat; public class Main { static DecimalFormat quantityDecimalFormat = new DecimalFormat("#,##0.###"); /** Formats an Long representing a quantity into a string * @param quantity The quantity Long to be formatted * @return A String with the formatted quantity */ public static String formatQuantity(Long quantity) { if (quantity == null) return ""; else return formatQuantity(quantity.doubleValue()); } /** Formats an int representing a quantity into a string * @param quantity The quantity long to be formatted * @return A String with the formatted quantity */ public static String formatQuantity(long quantity) { return formatQuantity((double) quantity); } /** Formats an Integer representing a quantity into a string * @param quantity The quantity Integer to be formatted * @return A String with the formatted quantity */ public static String formatQuantity(Integer quantity) { if (quantity == null) return ""; else return formatQuantity(quantity.doubleValue()); } /** Formats an int representing a quantity into a string * @param quantity The quantity int to be formatted * @return A String with the formatted quantity */ public static String formatQuantity(int quantity) { return formatQuantity((double) quantity); } /** Formats a Float representing a quantity into a string * @param quantity The quantity Float to be formatted * @return A String with the formatted quantity */ public static String formatQuantity(Float quantity) { if (quantity == null) return ""; else return formatQuantity(quantity.doubleValue()); } /** Formats a float representing a quantity into a string * @param quantity The quantity float to be formatted * @return A String with the formatted quantity */ public static String formatQuantity(float quantity) { return formatQuantity((double) quantity); } /** Formats an Double representing a quantity into a string * @param quantity The quantity Double to be formatted * @return A String with the formatted quantity */ public static String formatQuantity(Double quantity) { if (quantity == null) return ""; else return formatQuantity(quantity.doubleValue()); } /** Formats an BigDecimal representing a quantity into a string * @param quantity The quantity BigDecimal to be formatted * @return A String with the formatted quantity */ public static String formatQuantity(BigDecimal quantity) { if (quantity == null) return ""; else return quantityDecimalFormat.format(quantity); } /** Formats an double representing a quantity into a string * @param quantity The quantity double to be formatted * @return A String with the formatted quantity */ public static String formatQuantity(double quantity) { return quantityDecimalFormat.format(quantity); } }