Today, We want to share with you convert number to words in php.In this post we will show you convert number to rupees in php, hear for Converts Number to Words in Indian currency format with paise value we will give you demo and example for implement.In this post, we will learn about PHP Converts currency into number with an example.
Convert number to words in PHP
Example 1: index.php
<!DOCTYPE html> <html lang="en"> <head> <title>How to converts number to words using php - www.pakainfo.com</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link 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> <body class="bg-dark"> <div class="container"> <div class="row"> <div class="col-md-8 offset-md-2"> <div class="card mt-5"> <div class="card-header"> <h5>How To Converts Number To Words Using Php - www.pakainfo.com</h5> </div> <div class="card-body"> <form method="post"> <div class="form-group"> <label for="txtNumber">Enter Your Numbers:</label> <input type="number" class="form-control" id="txtNumber" placeholder="Enter Your Numbers" name="txtNumber"> </div> <button type="submit" class="btn btn-success">Converts</button><br/><br/> <?php if(isset($_POST['txtNumber'])){ $num = $_POST['txtNumber']; $get_amount= numberTowords($num); echo "<p align='center' class='text-danger'>".$get_amount."</p>"; } ?> </form> </div> </div> </div> </div> </div> </body> </html> <?php function numberTowords(float $volume) { $volume_after_decimal = round($volume - ($num = floor($volume)), 2) * 100; $amt_hundred = null; $count_length = strlen($num); $x = 0; $string = array(); $change_words = array(0 => '', 1 => 'One', 2 => 'Two', 3 => 'Three', 4 => 'Four', 5 => 'Five', 6 => 'Six', 7 => 'Seven', 8 => 'Eight', 9 => 'Nine', 10 => 'Ten', 11 => 'Eleven', 12 => 'Twelve', 13 => 'Thirteen', 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'); while( $x < $count_length ) { $get_divider = ($x == 2) ? 10 : 100; $volume = floor($num % $get_divider); $num = floor($num / $get_divider); $x += $get_divider == 10 ? 1 : 2; if ($volume) { $add_plural = (($counter = count($string)) && $volume > 9) ? 's' : null; $amt_hundred = ($counter == 1 && $string[0]) ? ' and ' : null; $string [] = ($volume < 21) ? $change_words[$volume].' '. $here_digits[$counter]. $add_plural.' '.$amt_hundred:$change_words[floor($volume / 10) * 10].' '.$change_words[$volume % 10]. ' '.$here_digits[$counter].$add_plural.' '.$amt_hundred; }else $string[] = null; } $implode_to_Rupees = implode('', array_reverse($string)); $get_paise = ($volume_after_decimal > 0) ? "And " . ($change_words[$volume_after_decimal / 10] . " " . $change_words[$volume_after_decimal % 10]) . ' Paise' : ''; return ($implode_to_Rupees ? $implode_to_Rupees . 'Rupees ' : '') . $get_paise; } ?>
I hope you get an idea about converts decimal number to rupees in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.