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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:45:07+00:00 2026-05-13T21:45:07+00:00

Say you have a string 3.4564. A sample set in the database has these

  • 0

Say you have a string 3.4564.

A sample set in the database has these records(VARCHAR):

Name       Score

Peter      3.35643294332
John       3.47870923
James      3.740249842
Henry      4.0432849
Solomon    3.456183923
Andrew     3.45743

You want to truncate 3.4564 to 3 decimal places(to become 3.456) then compare with the values of the database that when rounded to three decimal places will give the same value as 3.456 i.e. retrieve the name ‘Solomon’

What is the best way to go about it in php mysql?

  • 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-13T21:45:08+00:00Added an answer on May 13, 2026 at 9:45 pm

    If your score columns contains data stored as varchar, you could convert those to decimal, using the CAST function. For instance :

    mysql> select cast('3.35643294332' as decimal(10,3));
    +----------------------------------------+
    | cast('3.35643294332' as decimal(10,3)) |
    +----------------------------------------+
    |                                  3.356 |
    +----------------------------------------+
    1 row in set (0,01 sec)
    

    And note this will round the values correctly :

    mysql> select cast('3.35663294332' as decimal(10,3));
    +----------------------------------------+
    | cast('3.35663294332' as decimal(10,3)) |
    +----------------------------------------+
    |                                  3.357 |
    +----------------------------------------+
    1 row in set (0,00 sec)
    

    i.e. :

    • '3.3564' was casted to 3.356
    • and '3.3566' was casted to 3.357

    Now, you only have to use that cast function in your comparisons in your where clause.

    I suppose something like this should work, for instance :

    select * 
    from your_table
    where cast(Score as decimal(10,3)) = cast('3.4564' as decimal(10,3))
    

    i.e., you convert both the “input” and Score to decimals with 3 decimals ; and you convert those values.

    A a sidenote : doing so, you won’t be using any index that you might have on Score, and will always end up with a full-scan… Which means another solution would be better… For instance, if you could use a where clause like score >= X and Score <= Y, it would be much better…

    But, as Score is stored as varchar, it won’t be that easy, I suppose — you should store those as decimals, btw…

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

Sidebar

Related Questions

lets say I have a String like this [{ name : Ronald , firstname
Let's say I have a string with my class name inside: mystring = CDialogChild;
Say I have the string User Name:firstname.surname contained in a larger string how can
Say I have the string blöt träbåt which has a few a and o
Say I have the string s = Controller = require 'controller' class foo view:
say I have a string like so Testing How could I have it remove
Say I have a string. Then I have a number of unique tokens or
Say i have a string that i need to evaluate in javascript such as
Say I have a string 3434.35353 and another string 3593 How do I make
Say I have a string: the quick brown fox jumped over the moon.this text

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.