Software Utilities from Zyxware or other companies

Utilities more_horiz
close

on 08th December 2014 / by naveen.pl
I was faced with a requirement to convert number to words/string in Indian naming system with lakhs and crores. I had to generate the amount in words for printing it out on a bill. The total amount, provided to the customer, needed to be converted to string. For example, if 1345673 was to be converted to Thirteen lakh Forty Five Thousand Six Hundred and Seventy Three, these functions will have to be followed. Code is given below /** * Function to convert a number to a the string literal for the number */ function getStringOfAmount(\$num) { \$count = 0; global \$ones, \$tens, \$triplets; \$ones = array( '', ' One', ' Two', ' Three', ' Four', ' Five', ' Six', ' Seven', ' Eight', ' Nine', ' Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', ' Nineteen' ); \$tens = array( '', '', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', ' Ninety' ); \$triplets = array( '', ' Thousand', ' Million', ' Billion', ' Trillion', ' Quadrillion', ' Quintillion', ' Sextillion', ' Septillion', ' Octillion', ' Nonillion' ); return convertNum(\$num); } /** * Function to dislay tens and ones */ function commonloop(\$val, \$str1 = '', \$str2 = '') { global \$ones, \$tens; \$string = ''; if (\$val == 0) \$string .= \$ones[\$val]; else if (\$val &lt; 20) \$string .= \$str1.\$ones[\$val] . \$str2; else \$string .= \$str1 . \$tens[(int) (\$val / 10)] . \$ones[\$val % 10] . \$str2; return \$string; } /** * returns the number as an anglicized string */ function convertNum(\$num) { \$num = (int) \$num; // make sure it's an integer if (\$num &lt; 0) return 'negative' . convertTri(-\$num, 0); if (\$num == 0) return 'Zero'; return convertTri(\$num, 0); } /** * recursive fn, converts numbers to words */ function convertTri(\$num, \$tri) { global \$ones, \$tens, \$triplets, \$count; \$test = \$num; \$count++; // chunk the number, ...rxyy // init the output string \$str = ''; // to display hundred &amp; digits if (\$count == 1) { \$r = (int) (\$num / 1000); \$x = (\$num / 100) % 10; \$y = \$num % 100; // do hundreds if (\$x &gt; 0) { \$str = \$ones[\$x] . ' Hundred'; // do ones and tens \$str .= commonloop(\$y, ' and ', ''); } else if (\$r &gt; 0) { // do ones and tens \$str .= commonloop(\$y, ' and ', ''); } else { // do ones and tens \$str .= commonloop(\$y); } } // To display lakh and thousands else if(\$count == 2) { \$r = (int) (\$num / 10000); \$x = (\$num / 100) % 100; \$y = \$num % 100; \$str .= commonloop(\$x, '', ' Lakh '); \$str .= commonloop(\$y); if (\$str != '') \$str .= \$triplets[\$tri]; } // to display till hundred crore else if(\$count == 3) { \$r = (int) (\$num / 1000); \$x = (\$num / 100) % 10; \$y = \$num % 100; // do hundreds if (\$x &gt; 0) { \$str = \$ones[\$x] . ' Hundred'; // do ones and tens \$str .= commonloop(\$y,' and ',' Crore '); } else if (\$r &gt; 0) { // do ones and tens \$str .= commonloop(\$y,' and ',' Crore '); } else { // do ones and tens \$str .= commonloop(\$y); } } else { \$r = (int) (\$num / 1000); } // add triplet modifier only if there // is some output to be modified... // continue recursing? if (\$r &gt; 0) return convertTri(\$r, \$tri+1) . \$str; else return \$str; } Utilities Web Development PHP Leave a reply Your email address will not be published. Required fields are marker * Shridhar Sharma (not verified) access_time 20 Jun 2019 - 17:41 Your function is not working more than once in a php script. Add new comment more_horiz
close

on 01st November 2012 / by muhammed.junaid
As a web developer, we sometimes may want to export a specific table from a MySQL database. It can be particularly helpful when we are going to apply some changes to a table that is part of a large database and we are interested in backing up that specific table only, rather that whole huge database. To create a backup (also called dump) of the a table use this command: mysqldump -u username -p db_name table_name | gzip &gt; db_name.table_name.sql.gzThis will create the backup/dump for the table in the file in compressed format. We can import back the table to the database as usual we do with normal database dumps: gunzip -c db_name.table_name.sql.gz | mysql -u username -p db_nameUse the correct values for username, db_name and table_name. Linux Utilities Web Development MySQL Linux Terminal Leave a reply Your email address will not be published. Required fields are marker * more_horiz
close

on 28th January 2012 / by webmaster