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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
However, the disadvantage of this script is I have to enter all the numbers manually in the script which will result in unnecessarily and overwhelmingly large script.
Actually, the basic function which I want to achieve from this script is to remove all the numbers after the decimal point. For example, 2.667 should be converted to 2 and so on.
So, I think there must be a better way to write this script, instead of manually entering the numbers in the script.
Can you guide me towards the right-way to write this script? Thanks
However, the disadvantage of this script is I have to enter all the numbers manually in the script which will result in unnecessarily and overwhelmingly large script. Actually, the basic function which I want to achieve from this script is to remove all the numbers after the decimal point. For example, 2.667 should be converted to 2 and so on. So, I think there must be a better way to write this script, instead of manually entering the numbers in the script. Can you guide me towards the right-way to write this script?
pan64 gave a great answer, but I'll ask the question of "why?" How are these numbers getting in to whatever you're 'converting' in the first place?? Be far simpler to do the conversion there, versus later on. And rounding 2.667 to 2 would be rounding down...wouldn't 2.6 round UP to 3?
pan64 gave a great answer, but I'll ask the question of "why?" How are these numbers getting in to whatever you're 'converting' in the first place?? Be far simpler to do the conversion there, versus later on. And rounding 2.667 to 2 would be rounding down...wouldn't 2.6 round UP to 3?
The purpose here is just to remove the portion after decimal. It is nothing to do with rounding.
The purpose here is just to remove the portion after decimal. It is nothing to do with rounding.
Gotcha....still, it would seem to make more sense to have whatever is outputting these numbers print things the way you want, versus cleaning it up after.
Gotcha....still, it would seem to make more sense to have whatever is outputting these numbers print things the way you want, versus cleaning it up after.
The output is being created by Libreoffice calc. I know that we can adjust the output in Cell Properties > Number > Decimal.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.