Java Size getStringSize(String string)

Here you can find the source of getStringSize(String string)

Description

get String Size

License

LGPL

Declaration

public static final float getStringSize(String string) 

Method Source Code

//package com.java2s;
/**//from   ww  w  .  j av a  2  s.c om
 * Converts a line of text into an array of lower case words using a
 * BreakIterator.wordInstance().
 * <p>
 * <p/>
 * This method is under the Jive Open Source Software License and was
 * written by Mark Imbriaco.
 * 
 * @param text
 *            a String of text to convert into an array of words
 * @return text broken up into an array of words.
 */

import java.text.DecimalFormat;

public class Main {

    public static final float getStringSize(String string) {

        float size = 0f;
        if (string.length() > 0) {
            size = string.length() / 1024f;
        }

        size = size * 100;
        if (size > (int) size) {
            size = size + 1;
        }
        size = size / 100f;

        DecimalFormat format = new DecimalFormat("##.##");

        return Float.parseFloat(format.format(size));
    }
}

Related

  1. getSizeString(long bytes)
  2. getSizeString(long number, Locale locale)
  3. getSizeString(long size)
  4. getSizeText(long size)
  5. getSpaceSizeFromByte(long xB)
  6. padString(String stringToPad, int size)
  7. read(byte[] input, int size)
  8. readableBytes(long byteSize)
  9. readableSize(long num)