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 8002941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:31:19+00:00 2026-06-04T16:31:19+00:00

I am trying to check if a number which is inside a variable got

  • 0

I am trying to check if a number which is inside a variable got a decimal number above 50 , or less than 50. Then depending on if it’s 50 or higher, round the decimal number to 99 , and if it’s less, round it to 00.

Here is a piece of my code:

public function roundPrice($price)
{
return round( (ceil($price) - 0.01), 2);
}

It makes all decimal numbers round up to 99 . I would need only decimals which are 50 or higher to be rounded in 99, and 49 or less become 00.

How could I achieve this in PHP ? Many thanks, I’m stuck here and don’t know much how to do that.

  • 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-06-04T16:31:22+00:00Added an answer on June 4, 2026 at 4:31 pm

    On the off chance OP actually meant decimal places where 1.36 becomes 1.00 and 1.60 becomes 1.99.

    Probably more elegant solutions, but here’s one:

    function roundPrice($price)
    {
        $intVal = intval($price);
        if ($price - $intVal < .50) return (float)$intVal;
        return $intVal + 0.99;
    }
    

    http://codepad.org/5hIdQh4w

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to check if each number in a list is evenly divisible by
I am trying to find the fastest way to check whether a given number
I'm trying to check in jQuery if a div contains some text, and then
I am trying to validate a phone number which is contained over two fields.
I'm trying to number objects, which can be added to a cart with drag'n'drop.
I am trying to create a grammar which accepts any character or number or
I was trying to make a javascript function which will check if the user
I'm trying to check if a string is a number, so the regex \d+
I'm trying to set the credit card numbers based on the standard check parameters
I am trying to check if a date has passed or if it is

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.