2011年6月22日 星期三

Javascript 數值千分位顯示

function FormatNumber(n) {
    n += "";
    var arr = n.split(".");
    var re = /(\d{1,3})(?=(\d{3})+$)/g;
    return arr[0].replace(re,"$1,") + (arr.length == 2 ? "."+arr[1] : "");
}

//取消千分位:

nn = parseInt(v_p.replace(",",""),10);

//test   
document.write("1234567 -> " + FormatNumber(1234567) + "<br>");
document.write("12345678.12 -> " + FormatNumber("12345678.12") + "<br>");
document.write("123456789.1234 -> " + FormatNumber(123456789.1234) + "<br>");
document.write("-123456.123 ->" + FormatNumber(-123456.123) + "<br>");

引用來源

File MD5 Checksum

    Public Shared Function file_checksum(ByVal file_path As String) As String
        Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
        Dim fs As FileStream = New FileStream(file_path, FileMode.Open, FileAccess.Read, FileShare.Read)
        md5.ComputeHash(fs)

        Dim hash As Byte() = md5.Hash
        Dim buff As StringBuilder = New StringBuilder
        Dim hashByte As Byte
        For Each hashByte In hash
            buff.Append(String.Format("{0:X2}", hashByte))
        Next
        fs.Close()
        Return buff.ToString.Trim
    End Function