PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 11, 2022

[FIXED] How can I find values with more than 2 decimal places?

 August 11, 2022     decimal, sql     No comments   

Issue

I am validating data and trying to find if there are any values in a single column (allowed_amount) with more than 2 decimal places (24.1145678, 234.444, -1234.09012).

with t1 as (
  select (allowed_amount - round(allowed_amount,2)) as ck
  from export_core_report_client_output
  where runid = '0c7c2d34-6cc3-43b0-ae4b-4bd8f4bddfb0'
) 
select min(ck) as min, max(ck) as max from t1

Solution

One option would be to use this formula:

SELECT
    num,
    CASE WHEN 100*num - CAST(100*num AS int) > 0 THEN 'yes' ELSE 'no' END AS field
FROM yourTable;

Demo

For example, for the value 24.1234, the above formula computes:

2412.34 - 2412 = 0.34 > 0

But for 24.12, we get:

2412 - 2412 = 0


Answered By - Tim Biegeleisen
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing