简体   繁体   中英

How to write if condition to check numbers greater than or less than in php?

I have one input field where user will add numbers and in next label it will display that numbers in words. Basically user will input amount in number format and it will display in word format.And i have some conditions to show amount in words.

First condition is Amount should not greater than 10 digits.

Second condition is user can add money in decimal format.

eg: this is 1000000000.90 Allow (10 digits and then decimal point)

eg: this is 10000000000.90 Not Allow (decimal point after eleven digit)

So basically Amount length can go upto 13 digits with decimal point.

Without decimal Point it should be upto 10

For this I write below condition:

if(amount.length > 13){
   return 'please enter less amount';
}
if(amount.length > 10 && amount.includes('.') === false){
 return 'please enter less amount';
}

When i enter 11 digits and then decimal point 10000000000.0 it shows me amount in words but i want here to display error message because before decimal point there should be only 10 digits are allowed

So. Basically I want condition for allowd amount with decimal 13 digits and without decimal 1 digits only.please help me to solve this scenario. thanks in advance.

Okay so you want to allow numbers with those conditions so rather then use strlen and other functions why not just use maths.

Example

<?php
if($number <= 9999999999.99)
{
//Run the allowed code here
}
else
{
//Not allowed
}
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM