percentage of two int?

If you don’t add .0f it will be treated like it is an integer, and an integer division is a lot different from a floating point division indeed 🙂 float percent = (n * 100.0f) / v; If you need an integer out of this you can of course cast the float or the double … Read more

Decimal vs Double Speed

Floating point arithmetic will almost always be significantly faster because it is supported directly by the hardware. So far almost no widely used hardware supports decimal arithmetic (although this is changing, see comments). Financial applications should always use decimal numbers, the number of horror stories stemming from using floating point in financial applications is endless, … Read more

Javascript: How to retrieve the number of decimals of a *string* number?

function decimalPlaces(num) { var match = (”+num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/); if (!match) { return 0; } return Math.max( 0, // Number of digits right of decimal point. (match[1] ? match[1].length : 0) // Adjust for scientific notation. – (match[2] ? +match[2] : 0)); } The extra complexity is to handle scientific notation so decimalPlaces(‘.05’) 2 decimalPlaces(‘.5’) 1 decimalPlaces(‘1’) … Read more

Split an integer into digits to compute an ISBN checksum [duplicate]

Just create a string out of it. myinteger = 212345 number_string = str(myinteger) That’s enough. Now you can iterate over it: for ch in number_string: print ch # will print each digit in order Or you can slice it: print number_string[:2] # first two digits print number_string[-3:] # last three digits print number_string[3] # forth … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)