Timeline for How to do integer & float calculations, in bash or other languages/frameworks?
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 30, 2023 at 8:42 | comment | added | einpoklum | +1 on your critique of other methods, but lua, while useful, is still a bit on the heavy side and, more importantly, far from universally available. | |
| Sep 17, 2017 at 10:26 | comment | added | ndemou | I don't like the emphasis on what other answers got wrong. When looking for answers I personally expect the answer first. | |
| Oct 15, 2016 at 5:03 | history | edited | G-Man Says 'Reinstate Monica' | CC BY-SA 3.0 | Fixed formatting in example; tweaked wording. |
| Oct 19, 2015 at 12:09 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 | nothing to do with echo |
| May 1, 2013 at 19:54 | comment | added | Dalker | Just always use bc -l rather than plain bc, then never worry about scale. | |
| Jun 14, 2012 at 21:39 | comment | added | user unknown | Just count bc as one of the scripting languages. I always know whether I need integer results or not - if integer is alright I stay in bash, else I rarely have reason to use bc. For lua, you have to remember -e, print and parenthesis. | |
| Jun 14, 2012 at 17:06 | comment | added | manatwork | Personally I do remember about scale since I met bc first time years ago. But I always forgot whether the output function in lua is put or puts. ;) | |
| Jun 14, 2012 at 16:53 | history | edited | Marco | CC BY-SA 3.0 | Correct and improve examples |
| Jun 14, 2012 at 16:26 | comment | added | Marco | Thanks for the correction. But still, it's error prone. Will I remeber to add scale if I use bc in a couple of weeks? Probably not. And even if there's a way to change it permanently, it will bite you if you're on a system with the default settings. | |
| Jun 14, 2012 at 16:16 | comment | added | manatwork | bc's result is not integer, just rounded to scale, who's default value is 0. So bc <<< 'scale=4;9.0/2.0' if you want the fractional part. | |
| Jun 14, 2012 at 15:55 | history | answered | Marco | CC BY-SA 3.0 |