ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
hello all,
I'm trying to do a calculation of the following all simple in itself but with the inclusion of something like significant figures. eg:
i want to do something like 10-1 = 09 and not 9
what i do at the moment is
x=10
y=$(($x-1))
that comes to 9 but i'm looking for 09 as the answer. and i know if you can set sig fig's to 2. then i should get the answer 09. The only other way i can think of doing it would be to read in the variable "x" count the number of characters in the variable and if its only one character add a 0 at the begining as i'm only using numbers from 01-99
wow LoL what a simple and yet brilliant idea hehe, now i wish i'd thought of that. Thanks dude thats cool. Yeah i can write that fine in bash No Probs. But if there is a tool that does it properly if anyone knows then let me know cos i'll still be interested. But thanks to that person above
cheers again hit the target right on the noggin. Thanks again i dont know what that thing is "printf" but sure am going to look into it looks like i might be able to use it in some other places as well so thanks very much peeps
see told you it was simple. but its only simple to those who are in the know
Well, glance through POSIX. Glance through GNU coreutils list (even better - POSIX is theory, coreutils are practice). Until you do it you miss a lot when bash scripting.
thanks but erm as bad as it might be to say this, what is posix and the other thing, i'm guessing some sort of documentation or "man" entries?? sorry am near to being a newb after all.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.