How can I format a String number to have commas and round?

You might want to look at the DecimalFormat class; it supports different locales (eg: in some countries that would get formatted as 1.000.500.000,57 instead). You also need to convert that string into a number, this can be done with: double amount = Double.parseDouble(number); Code sample: String number = “1000500000.574”; double amount = Double.parseDouble(number); DecimalFormat formatter … Read more

Format number to 2 decimal places

When formatting number to 2 decimal places you have two options TRUNCATE and ROUND. You are looking for TRUNCATE function. Examples: Without rounding: TRUNCATE(0.166, 2) — will be evaluated to 0.16 TRUNCATE(0.164, 2) — will be evaluated to 0.16 docs: http://www.w3resource.com/mysql/mathematical-functions/mysql-truncate-function.php With rounding: ROUND(0.166, 2) — will be evaluated to 0.17 ROUND(0.164, 2) — will … Read more

Integer to hex string in C++

Use <iomanip>‘s std::hex. If you print, just send it to std::cout, if not, then use std::stringstream std::stringstream stream; stream << std::hex << your_int; std::string result( stream.str() ); You can prepend the first << with << “0x” or whatever you like if you wish. Other manips of interest are std::oct (octal) and std::dec (back to decimal). … Read more

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