MarketDisplayBaseImpl implements MarketDisplay { @Override public String priceText(PriceValue price, Fraction frac) { if(price == null) { price = ValueConst.NULL_PRICE; } if(frac == null) { } long mantissa = price.mantissa(); int exponent = price.exponent(); boolean isMinus; if (mantissa < 0) { mantissa = -mantissa; isMinus = true; } else { isMinus = false; } final long scale = frac.exponent(); while (exponent > scale) { mantissa *= 10; exponent--; } while (exponent < scale) { mantissa /= 10; exponent++; } long whole = frac.priceWhole(mantissa, exponent); final char separator; if(frac.base() == 10) { mantissa %= frac.denominator(); separator = ASCII.DOT; } else { mantissa %= frac.decimalDenominator(); mantissa *= frac.denominator(); mantissa /= frac.decimalDenominator(); separator = ASCII.DASH; } long part = mantissa; final int size = 64; final char[] array = new char[size]; int index = size - 1; long places = frac.places(); if(frac.base() == 10) { places--; } if (places > 0) { for (int k = 0; k < places; k++) { final char alpha = (char) (part % 10 + ASCII._0_); array[index--] = alpha; part /= 10; } array[index--] = separator; } if (whole == 0) { array[index--] = ASCII._0_; } else { while (whole != 0) { final char alpha = (char) (whole % 10 + ASCII._0_); array[index--] = alpha; whole /= 10; } if (isMinus) { array[index--] = ASCII.MINUS; } } final int offset = index + 1; final int length = size - offset; return new String(array, offset, length); }  @Override String timeYearFull(TimeValue time); @Override String timeYearShort(TimeValue time); @Override String timeMonthFull(TimeValue time); @Override String timeMonthShort(TimeValue time); @Override String timeMonthCode(TimeValue time); @Override String priceFractionText(PriceValue price, Fraction frac); @Override String priceText(PriceValue price, Fraction frac); @Override String priceText(PriceValue price, long base, long exponent); @Override String priceText(long mantissa, int exponent, long base, long baseExp); @Override String sizeText(SizeValue size); @Override String sizeText(long size); @Override String timeTextISO(TimeValue value); @Override String timeTextShort(TimeValue value); @Override String dateTimeText(TimeValue value); @Override String dateTextShort(TimeValue value); @Override String timeTextShort(TimeValue value, DateTimeZone zone);  }
@Test public void testPriceText() { PriceValue price; String text; price = newPrice(181925, -2); text = display.priceText(price, DEC_N02); System.out.println("price : " + text); assertEquals("1819.25", text); price = newPrice(181900, -2); text = display.priceText(price, DEC_N02); System.out.println("price : " + text); assertEquals("1819.00", text); price = newPrice(181925, -2); text = display.priceText(price, BIN_N02); System.out.println("price : " + text); assertEquals("1819-1", text); price = newPrice(181975, -2); text = display.priceText(price, BIN_N02); System.out.println("price : " + text); assertEquals("1819-3", text); price = newPrice(1819125, -3); text = display.priceText(price, BIN_N03); System.out.println("price : " + text); assertEquals("1819-1", text); price = newPrice(1819250, -3); text = display.priceText(price, BIN_N03); System.out.println("price : " + text); assertEquals("1819-2", text); price = newPrice(18191250, -4); text = display.priceText(price, BIN_N04); System.out.println("price : " + text); assertEquals("1819-02", text); price = newPrice(20234375, -7); text = display.priceText(price, BIN_N07); System.out.println("price : " + text); assertEquals("2-003", text); price = newPrice(181925, -3); text = display.priceText(price, DEC_N04); System.out.println("price : " + text); assertEquals("181.9250", text); price = newPrice(181925, -2); text = display.priceText(price, DEC_N04); System.out.println("price : " + text); assertEquals("1819.2500", text); price = newPrice(1819, 0); text = display.priceText(price, DEC_N03); System.out.println("price : " + text); assertEquals("1819.000", text); price = newPrice(-1819, 0); text = display.priceText(price, DEC_N03); System.out.println("price : " + text); assertEquals("-1819.000", text); price = newPrice(18195, -1); text = display.priceText(price, DEC_N02); System.out.println("price : " + text); assertEquals("1819.50", text); price = newPrice(-1, 0); text = display.priceText(price, DEC_Z00); System.out.println("price : " + text); assertEquals("-1", text); price = newPrice(-1, 0); text = display.priceText(price, DEC_N02); System.out.println("price : " + text); assertEquals("-1.00", text); price = newPrice(-125, -2); text = display.priceText(price, DEC_N02); System.out.println("price : " + text); assertEquals("-1.25", text); price = newPrice(175, -2); text = display.priceText(price, BIN_N02); System.out.println("price : " + text); assertEquals("1-3", text); price = newPrice(-175, -2); text = display.priceText(price, BIN_N02); System.out.println("price : " + text); assertEquals("-1-3", text); }