×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

I want a value 134.45678MHz in only MHz - can perl do it?

I want a value 134.45678MHz in only MHz - can perl do it?

I want a value 134.45678MHz in only MHz - can perl do it?

(OP)
Thats it. I want a number to only 3 significant bits ie MHz.

Gordon Bell
gordon.bell@xilinx.com

RE: I want a value 134.45678MHz in only MHz - can perl do it?

The function int() will return just the integer portion (numbers in front of the decimal point) for you -- would that be sufficient or did you want rounding?

Mike
michael.j.lacey@ntlworld.com
Cargill's Corporate Web Site
Please -- Don't send me email questions without posting them in Tek-Tips as well. Better yet -- Post the question in Tek-Tips and send me a note saying "Have a look at so-and-so in the thingy forum would you?"

RE: I want a value 134.45678MHz in only MHz - can perl do it?

Print to a string with format control for the accuracy you want, then convert back to floating point using atof(), which returns double precision.

Octalman


RE: I want a value 134.45678MHz in only MHz - can perl do it?

Oops.  Wrong language.

Octalman


RE: I want a value 134.45678MHz in only MHz - can perl do it?

INAPG (I'm not a Perl Guru), so maybe I can learn something here too.  How about $val = $val * 1000; $temp = pack l, $val; $newval = (int $temp)/1000; ?  I don't see any type conversions in the module library, but that may have changed.

Octalman


RE: I want a value 134.45678MHz in only MHz - can perl do it?

As an alternative to Mike's suggestion, and to show Octal was right, even if he had the wrong language (;^), try this:

#!/usr/bin/perl
$Value=134.45678;

$Mhz = sprintf("%3d", $Value);

print $Mhz, "\n";


Note - this does not do any rounding, so 134.444 will be 134, as will 134.888.

RE: I want a value 134.45678MHz in only MHz - can perl do it?

(OP)
Thanks - that has been a great help

Gordon Bell
gordon.bell@xilinx.com

RE: I want a value 134.45678MHz in only MHz - can perl do it?

(OP)
Thanks Andy - how did you get that postfix?

Gordon Bell
gordon.bell@xilinx.com

RE: I want a value 134.45678MHz in only MHz - can perl do it?

The postfix on my member name? "Bo"?  Abbreviation of my second name that's been used in other places, so it's easy for me to remember :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close