Solved

how to convert from a floating point number to a decimal number?

Posted on 1998-12-16
2
150 Views
Last Modified: 2010-03-05
I have a floating point variable $fp.
I want to copy its value in decimal integer format to the variable $di.
For example, if $fp=354.34, I want $di=354
             if $fp=354.55, I want $di=355
How do I do this? Thanks.
0
Comment
Question by:djc2
2 Comments
 
LVL 1

Accepted Solution

by:
flivauda earned 50 total points
ID: 1206973
#!/usr/local/bin/perl

$fp=354.34;
$di = sprintf("%.0f",$fp);
print "Rounded: $di\n";

$fp=354.55;
$di = sprintf("%.0f",$fp);
print "Rounded: $di\n";




0
 

Author Comment

by:djc2
ID: 1206974
Thanks! Just what I needed.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

816 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