Jump to content

How to get the rupee value in words


lak

Recommended Posts

Hi,I m doing billing project in PHP, In that final result is the TOTAL AMOUNT in numbers, i want that amount in words also (e.g)Rs.23000. Rupees twenty three thousand only.How to do that.Please help me as soon as possible

Link to comment
Share on other sites

You'll need to write a function that will calculate the string for that. It needs to have a maximum amount, whatever you want that to be. Here's a function that works for numbers up to the thousands, you can expand this to add millions or billions or whatever else.

function write_num($val){  if (floor($val / 1000) > 0)  {	$temp = floor($val / 1000);	$val -= $temp * 1000;	echo write_num($temp) . "thousand ";	if ($val == 0)	  return;  }  if (floor($val / 100) > 0)  {	$temp = floor($val / 100);	$val -= $temp * 100;	echo write_num($temp) . "hundred ";	if ($val == 0)	  return;  }  if ($val > 19)  {	if (floor($val / 10) > 0)	{	  $temp = floor($val / 10);	  $val -= $temp * 10;	  switch ($temp)	  {		case 9:		  echo "ninety";		  break;		case 8:		  echo "eighty";		  break;		case 7:		  echo "seventy";		  break;		case 6:		  echo "sixty";		  break;		case 5:		  echo "fifty";		  break;		case 4:		  echo "fourty";		  break;		case 3:		  echo "thirty";		  break;		case 2:		  echo "twenty";		  break;	  }	  if ($val > 0)	  {		echo "-";		write_num($val);	  }	}  }  else  {	switch ($val)	{	  case 19:		echo "nineteen ";		break;	  case 18:		echo "eighteen ";		break;	  case 17:		echo "seventeen ";		break;	  case 16:		echo "sixteen ";		break;	  case 15:		echo "fifteen ";		break;	  case 14:		echo "fourteen ";		break;	  case 13:		echo "thirteen ";		break;	  case 12:		echo "twelve ";		break;	  case 11:		echo "eleven ";		break;	  case 10:		echo "ten ";		break;	  case 9:		echo "nine ";		break;	  case 8:		echo "eight ";		break;	  case 7:		echo "seven ";		break;	  case 6:		echo "six ";		break;	  case 5:		echo "five ";		break;	  case 4:		echo "four ";		break;	  case 3:		echo "three ";		break;	  case 2:		echo "two ";		break;	  case 1:		echo "one ";		break;	  case 0:		echo "zero ";		break;	}  }}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...