Solved

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

Posted on 1998-12-16
2
147 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

20 Experts available now in Live!

Get 1:1 Help Now