package com.genlot.ninglottery.toolkit;

import android.text.TextUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;

public class StringTool {

    private static DecimalFormat format1 = new DecimalFormat("0.00");
    private static DecimalFormat format2 = new DecimalFormat("00");

    //字符串MD5加密
    public static String md5(String string) {
        if (TextUtils.isEmpty(string)) {
            return "";
        }
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            byte[] bytes = md5.digest(string.getBytes());
            String result = "";
            for (byte b : bytes) {
                String temp = Integer.toHexString(b & 0xff);
                if (temp.length() == 1) {
                    temp = "0" + temp;
                }
                result += temp;
            }
            return result;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }


    public static String format1(float number) {
        return format1.format(number);
    }

    public static String format1(double number) {
        return format1.format(number);
    }

    public static String format1(long number) {
        return format1.format(number);
    }

    public static String format2(int number) {
        return format2.format(number);
    }
}
