Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7035891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:21:31+00:00 2026-05-28T01:21:31+00:00

in my ksh script I need to calculate only integer numbers Sometimes I get

  • 0

in my ksh script I need to calculate only integer numbers

Sometimes I get float numbers such as 3.49 or 4.8…etc

so I need to translate the float numbers to integer’s numbers according to the following rules (examples)

3.49     will be 3
2.9      will be 3
4.1      will be 4
23.51    will be 24
982.4999 will be 982

10.5     will be 11  ( this example if float is .5 then it will roundup )

Please advice how to do this in ksh or awk or perl

Or

any other language that can be run in my ksh script

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:21:32+00:00Added an answer on May 28, 2026 at 1:21 am

    After a brief google session, I found that printf seems to be able to do the job, at least in bash (couldn’t find an online interpreter that does ksh).

    printf "%0.f\n" 4.51
    5
    printf "%0.f\n" 4.49
    4
    

    Code at: http://ideone.com/nEFYF

    Note: perl might be overkill, like Marius says, but here’s a perl way:

    The perl module Math::Round seems to handle the job.

    One-liner:

    perl -MMath::Round -we 'print round $ARGV[0]' 12.49
    

    Script:

    use v5.10;
    use Math::Round;
    my @list = (3.49, 2.9, 4.1, 23.51, 982.4999);
    
    say round $_ for @list;
    

    Script output:

    3
    3
    4
    24
    982
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the following question relevant for ksh script how to calculate the NETWORK IP according
In the following very simple ksh script example, I need to ask if func1
The following Ksh script gives me No such file or directory error message on
need advice about the following with the following ksh script I actually copy file1
I have written a KornShell (ksh) script that sets an array the following way:
I've just found the following code in a ksh script: if [ ${file_id} =
the following test syntax is part of ksh script [[ $PARAM = TRUE ]]
I need to run Java from KSH script after getting a list of files
I have a problem with the following ksh script: #! /usr/bin/ksh EXCLUDE+= --exclude '/bin/a*'
I need to tokenize in string in KornShell (ksh). I have got the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.