{"id":658,"date":"2012-10-25T06:23:07","date_gmt":"2012-10-25T06:23:07","guid":{"rendered":"http:\/\/codeatelier.wordpress.com\/?p=354"},"modified":"2012-10-25T06:23:07","modified_gmt":"2012-10-25T06:23:07","slug":"php-number-to-words-rupee","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/php-number-to-words-rupee\/","title":{"rendered":"PHP Number to Words Rupee"},"content":{"rendered":"<pre>\n\t\/\/taking number as parameter\n\tfunction convert_digit_to_words($no)  \n\t{   \n\t\n\t\/\/creating array  of word for each digit\n\t $words = array('0'=&gt; 'Zero' ,'1'=&gt; 'one' ,'2'=&gt; 'two' ,'3' =&gt; 'three','4' =&gt; 'four','5' =&gt; 'five','6' =&gt; 'six','7' =&gt; 'seven','8' =&gt; 'eight','9' =&gt; 'nine','10' =&gt; 'ten','11' =&gt; 'eleven','12' =&gt; 'twelve','13' =&gt; 'thirteen','14' =&gt; 'fourteen','15' =&gt; 'fifteen','16' =&gt; 'sixteen','17' =&gt; 'seventeen','18' =&gt; 'eighteen','19' =&gt; 'nineteen','20' =&gt; 'twenty','30' =&gt; 'thirty','40' =&gt; 'forty','50' =&gt; 'fifty','60' =&gt; 'sixty','70' =&gt; 'seventy','80' =&gt; 'eighty','90' =&gt; 'ninty','100' =&gt; 'hundred','1000' =&gt; 'thousand','100000' =&gt; 'lac','10000000' =&gt; 'crore');\n\t \/\/$words = array('0'=&gt; '0' ,'1'=&gt; '1' ,'2'=&gt; '2' ,'3' =&gt; '3','4' =&gt; '4','5' =&gt; '5','6' =&gt; '6','7' =&gt; '7','8' =&gt; '8','9' =&gt; '9','10' =&gt; '10','11' =&gt; '11','12' =&gt; '12','13' =&gt; '13','14' =&gt; '14','15' =&gt; '15','16' =&gt; '16','17' =&gt; '17','18' =&gt; '18','19' =&gt; '19','20' =&gt; '20','30' =&gt; '30','40' =&gt; '40','50' =&gt; '50','60' =&gt; '60','70' =&gt; '70','80' =&gt; '80','90' =&gt; '90','100' =&gt; '100','1000' =&gt; '1000','100000' =&gt; '100000','10000000' =&gt; '10000000');\n\t \n\t \n\t \/\/for decimal number taking decimal part\n\t \n\t$cash=(int)$no;  \/\/take number wihout decimal\n\t$decpart = $no - $cash; \/\/get decimal part of number\n\t\n\t$decpart=sprintf(\"%01.2f\",$decpart); \/\/take only two digit after decimal\n\t\n\t$decpart1=substr($decpart,2,1); \/\/take first digit after decimal\n\t$decpart2=substr($decpart,3,1);   \/\/take second digit after decimal  \n\t\n\t$decimalstr='';\n\t\n\t\/\/if given no. is decimal than  preparing string for decimal digit's word\n\t\n\tif($decpart&gt;0)\n\t{\n\t $decimalstr.=\"point \".$numbers[$decpart1].\" \".$numbers[$decpart2];\n\t}\n\t \n\t    if($no == 0)\n\t        return ' ';\n\t    else {\n\t    $novalue='';\n\t    $highno=$no;\n\t    $remainno=0;\n\t    $value=100;\n\t    $value1=1000;       \n\t            while($no&gt;=100)    {\n\t                if(($value &lt;= $no) &amp;&amp;($no  &lt; $value1))    {\n\t                $novalue=$words[&quot;$value&quot;];\n\t                $highno = (int)($no\/$value);\n\t                $remainno = $no % $value;\n\t                break;\n\t                }\n\t                $value= $value1;\n\t                $value1 = $value * 100;\n\t            }       \n\t          if(array_key_exists(&quot;$highno&quot;,$words))  \/\/check if $high value is in $words array\n\t              return $words[&quot;$highno&quot;].&quot; &quot;.$novalue.&quot; &quot;.convert_digit_to_words($remainno).$decimalstr;  \/\/recursion\n\t          else {\n\t             $unit=$highno%10;\n\t             $ten =(int)($highno\/10)*10;\n\t             return $words[&quot;$ten&quot;].&quot; &quot;.$words[&quot;$unit&quot;].&quot; &quot;.$novalue.&quot; &quot;.convert_digit_to_words($remainno\n\t             ).$decimalstr; \/\/recursion\n\t           }\n\t    }\n\t}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\/\/taking number as parameter function convert_digit_to_words($no) { \/\/creating array of word for each digit $words = array(&#8216;0&#8217;=&gt; &#8216;Zero&#8217; ,&#8217;1&#8217;=&gt; &#8216;one&#8217; ,&#8217;2&#8217;=&gt; &#8216;two&#8217; ,&#8217;3&#8242; =&gt; &#8216;three&#8217;,&#8217;4&#8242; =&gt; &#8216;four&#8217;,&#8217;5&#8242; =&gt; &#8216;five&#8217;,&#8217;6&#8242; =&gt; &#8216;six&#8217;,&#8217;7&#8242; =&gt; &#8216;seven&#8217;,&#8217;8&#8242; =&gt; &#8216;eight&#8217;,&#8217;9&#8242; =&gt; &#8216;nine&#8217;,&#8217;10&#8217; =&gt; &#8216;ten&#8217;,&#8217;11&#8217; =&gt; &#8216;eleven&#8217;,&#8217;12&#8217; =&gt; &#8216;twelve&#8217;,&#8217;13&#8217; =&gt; &#8216;thirteen&#8217;,&#8217;14&#8217; =&gt; &#8216;fourteen&#8217;,&#8217;15&#8217; =&gt; &#8216;fifteen&#8217;,&#8217;16&#8217; =&gt; &#8216;sixteen&#8217;,&#8217;17&#8217; =&gt; &#8216;seventeen&#8217;,&#8217;18&#8217; =&gt; &#8216;eighteen&#8217;,&#8217;19&#8217;&hellip; <a href=\"https:\/\/codethataint.com\/blog\/php-number-to-words-rupee\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93],"tags":[],"class_list":["post-658","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=658"}],"version-history":[{"count":0,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/658\/revisions"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}