php: number only hash?

An MD5 or SHA1 hash in PHP returns a hexadecimal number, so all you need to do is convert bases. PHP has a function that can do this for you: $bignum = hexdec( md5(“test”) ); or $bignum = hexdec( sha1(“test”) ); PHP Manual for hexdec Since you want a limited size number, you could then … Read more

Double multiplied by 100 and then cast to long is giving wrong value

None of the answers seem to deal with why 17.32 acted different. 1. Why it occurred The difference in behaviour you see between 17.32 and 17.33 & 17.31 is due to IEEE-754 Rounding rules. Rounding rule applied: from, The Java™ Virtual Machine Specification §2.8.1 The rounding operations of the Java virtual machine always use IEEE … Read more

Format a number with leading sign

Use a negative subpattern, as described in the javadoc for DecimalFormat. DecimalFormat fmt = new DecimalFormat(“+#,##0.00;-#”); System.out.println(fmt.format(98787654.897)); System.out.println(fmt.format(-98787654.897)); produces (in my French locale where space is the grouping separator and the comma is the decimal separator) : +98 787 654,90 -98 787 654,90