Solved

Adding places in decimals

Posted on 2000-04-05
2
149 Views
Last Modified: 2010-03-05
I am doing a little bit of adding in a script, but when I add the numbers, the script removes the decimal or some of the places after the decimal.

For example: 24.50 + 24.50 = 89
             24.50 = 24.5

I need to keep the 2 places after the decimal. How can I do that?
0
Comment
Question by:kch011099
2 Comments
 
LVL 1

Accepted Solution

by:
sbuehrle earned 25 total points
ID: 2687541
Use printf instead of print.
0
 
LVL 84

Expert Comment

by:ozo
ID: 2687868
printf "%.2f",24.50 + 24.50;
#or work with exact integer cents instead of approximate floating dollars to avoid round off errors
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now