[javascript]
/**
* Format a number to display thousands like in the US -> 1000000 => 1,000,000
* @param number
* @returns
*/
function formatThousands(number) {
return Math.max(0, number).toFixed(0).replace(/(?=(?:d{3})+$)(?!^)/g, ‘,’);
}
[/javascript]
Related Posts
Bash Alias – “svn_diff_counter”: Count lines added and removed
I love to know how many lines I’ve added and deleted before making a commit. This is why I created this alias: alias svn_diff_counter=’svn diff | egrep “^[+|-].*” | egrep -v “(+++)|(—)” > .tmp_diff_counter ; added=`egrep “(^+)” .tmp_diff_counter | wc -l`; removed=`egrep “(^-)” .tmp_diff_counter | wc -l`; rm .tmp_diff_counter; echo “Lines Added vs. Line Removed […]
Top Eclipse (IDE) features I can’t live without
(If you are in Windows, replace “Cmd” for “Ctrl”, and “Option” for “Alt”) Cmd + 1: Create variables out of function’s outputs, get suggestions to fix issues. “Shift + Cmd + T”: Open Type. “Shift + Cmd + R”: Open Resource. Select element and press “Option + Cmd + R” to rename a class, variable, […]
[CODE] Arduino 4 BIT LED binary counter
Here’s my “Hello World” on Arduino. A 4-bit binary counter for arduino. If you add another LED on the 5th pin, then it can count from 0 to 31 (32 values) Circuit wired by @KataySantos [pastacode lang=”c” manual=”int%20counter%20%3D%20-1%3B%0Aint%20MAX_VALUE%20%3D%2016%3B%0A%0Avoid%20updateLED(int%20pin%2C%20int%20bit%2C%20int%20ctr)%20%7B%0A%20%20digitalWrite(pin%2C%20(ctr%20%26%20(1%3C%3Cbit))%20%3D%3D%20(1%3C%3Cbit)%20%3F%20HIGH%20%3A%20LOW)%3B%0A%7D%0Avoid%20setup()%20%7B%0A%20%20%2F%2F%20this%20runs%20once%0A%20%20pinMode(1%2C%20OUTPUT)%3B%0A%20%20pinMode(2%2C%20OUTPUT)%3B%0A%20%20pinMode(3%2C%20OUTPUT)%3B%0A%20%20pinMode(4%2C%20OUTPUT)%3B%0A%7D%0A%0Avoid%20loop()%20%7B%0A%20%20%2F%2F%20this%20runs%20repeatedly%0A%20%20counter%20%3D%20(counter%20%2B%201)%20%25%20MAX_VALUE%3B%0A%20%20updateLED(1%2C%200%2C%20counter)%3B%0A%20%20updateLED(2%2C%201%2C%20counter)%3B%0A%20%20updateLED(3%2C%202%2C%20counter)%3B%0A%20%20updateLED(4%2C%203%2C%20counter)%3B%0A%20%20delay(500)%3B%0A%7D” message=”” highlight=”” provider=”manual”/]