Convert Number To Words In PHP

Hello Dev,

At the moment, i we are going to present you exchange quantity to phrases in php. This text offers you easy instance of convert quantity to phrases in php. you’ll convert quantity to phrases in php. On this article, we are going to implement a convert quantity to phrases in php.

So let’s observe few step to create instance of convert quantity to phrases in php.

Convert Number To Words In PHP

Instance


<!DOCTYPE html>
<html lang="en">
<head>
  <title>convert quantity to phrases in php</title>
  <meta charset="utf-8">
  <meta identify="viewport" content material="width=device-width, initial-scale=1">
  <hyperlink rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.js"></script>
</head>
<physique class="bg-dark">
<div class="container">
  <div class="row">
    <div class="col-md-Eight offset-md-2">
      <div class="card mt-5">
        <div class="card-header">
          <h5>Convert Quantity To Phrases In PHP</h5>
        </div>
        <div class="card-body">
            <type methodology="submit">
              <div class="form-group">
                <label for="txtNumber">Enter Your Numbers:</label>
                <enter kind="quantity" class="form-control" id="txtNumber" placeholder="Enter Your Numbers" identify="txtNumber">
              </div>
              <button kind="submit" class="btn btn-success">Convert</button><br/><br/>
               <?php
                 if(isset($_POST['txtNumber'])){
                   $num = $_POST['txtNumber'];
                   $get_amount= numberTowords($num);
                   echo "<p align='middle' class="text-danger">".$get_amount."</p>";
                   }
               ?>
          </type>
        </div>
      </div>
    </div>
  </div>
</div>
</physique>
</html>

<?php
// Create a operate for changing the quantity in phrases
operate numberTowords(float $quantity)
{
   $amount_after_decimal = spherical($quantity - ($num = flooring($quantity)), 2) * 100;
   // Examine if there's any quantity after decimal
   $amt_hundred = null;
   $count_length = strlen($num);
   $x = 0;
   $string = array();
   $change_words = array(0 => '', 1 => 'One', 2 => 'Two',
     3 => 'Three', 4 => '4', 5 => '5', 6 => 'Six',
     7 => 'Seven', 8 => 'Eight', 9 => '9',
     10 => 'Ten', 11 => 'Eleven', 12 => 'Twelve',
     13 => '13', 14 => 'Fourteen', 15 => 'Fifteen',
     16 => 'Sixteen', 17 => 'Seventeen', 18 => 'Eighteen',
     19 => 'Nineteen', 20 => 'Twenty', 30 => 'Thirty',
     40 => 'Forty', 50 => 'Fifty', 60 => 'Sixty',
     70 => 'Seventy', 80 => 'Eighty', 90 => 'Ninety');
  $here_digits = array('', 'Hundred','Thousand','Lakh', 'Crore');
  whereas( $x < $count_length ) {
       $get_divider = ($x == 2) ? 10 : 100;
       $quantity = flooring($num % $get_divider);
       $num = flooring($num / $get_divider);
       $x += $get_divider == 10 ? 1 : 2;
       if ($quantity) {
         $add_plural = (($counter = depend($string)) && $quantity > 9) ? 's' : null;
         $amt_hundred = ($counter == 1 && $string[0]) ? ' and ' : null;
         $string [] = ($quantity < 21) ? $change_words[$amount].' '. $here_digits[$counter]. $add_plural.' 
         '.$amt_hundred:$change_words[floor($amount / 10) * 10].' '.$change_words[$amount % 10]. ' 
         '.$here_digits[$counter].$add_plural.' '.$amt_hundred;
         }else $string[] = null;
       }
   $implode_to_Rupees = implode('', array_reverse($string));
   $get_paise = ($amount_after_decimal > 0) ? "And " . ($change_words[$amount_after_decimal / 10] . " 
   " . $change_words[$amount_after_decimal % 10]) . ' Paise' : '';
   return ($implode_to_Rupees ? $implode_to_Rupees . 'Rupees ' : '') . $get_paise;
}
 
?>

I hope it’ll help you…

Komentar

Postingan populer dari blog ini

PHP 8 Multiple Select Dropdown Example

Laravel 8 Get HTTP Hostname

JQuery Drag And Drop Menu Example