Raju Fodse

Raju Fodse

  • 1.4k
  • 244
  • 29.5k

How to create custom helper for converting Number to word

Sep 18 2020 2:38 AM
I am developing web app using I want to display currency amount in word and I want to use custome HTML helper. How can I call function in HTML Helper.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6.   
  7. namespace EasyApp.Models  
  8. {  
  9.     public static class NWConverter  
  10.     {  
  11.   
  12.         public static IHtmlString Retrieve_Label(this HtmlHelper helper)  
  13.         {  
  14.             //I want use this html helper  
  15.         }  
  16.   
  17.         public string Rupees(Int32 rup)  
  18.         {  
  19.             string result = "";  
  20.             Int32 res;  
  21.             if ((rup / 10000000) > 0)  
  22.             {  
  23.                 res = rup / 10000000;  
  24.                 rup = rup % 10000000;  
  25.                 result = result + ' ' + RupeesToWords(res) + " Crore";  
  26.             }  
  27.             if ((rup / 100000) > 0)  
  28.             {  
  29.                 res = rup / 100000;  
  30.                 rup = rup % 100000;  
  31.                 result = result + ' ' + RupeesToWords(res) + " Lack";  
  32.             }  
  33.             if ((rup / 1000) > 0)  
  34.             {  
  35.                 res = rup / 1000;  
  36.                 rup = rup % 1000;  
  37.                 result = result + ' ' + RupeesToWords(res) + " Thousand";  
  38.             }  
  39.             if ((rup / 100) > 0)  
  40.             {  
  41.                 res = rup / 100;  
  42.                 rup = rup % 100;  
  43.                 result = result + ' ' + RupeesToWords(res) + " Hundred";  
  44.             }  
  45.             if ((rup % 10) >= 0)  
  46.             {  
  47.                 res = rup % 100;  
  48.                 result = result + " " + RupeesToWords(res);  
  49.             }  
  50.             result = result + ' ' + " Rupees only";  
  51.             return result;  
  52.         }  
  53.         public string RupeesToWords(Int32 rup)  
  54.         {  
  55.             string result = "";  
  56.             if ((rup >= 1) && (rup <= 10))  
  57.             {  
  58.                 if ((rup % 10) == 1) result = "One";  
  59.                 if ((rup % 10) == 2) result = "Two";  
  60.                 if ((rup % 10) == 3) result = "Three";  
  61.                 if ((rup % 10) == 4) result = "Four";  
  62.                 if ((rup % 10) == 5) result = "Five";  
  63.                 if ((rup % 10) == 6) result = "Six";  
  64.                 if ((rup % 10) == 7) result = "Seven";  
  65.                 if ((rup % 10) == 8) result = "Eight";  
  66.                 if ((rup % 10) == 9) result = "Nine";  
  67.                 if ((rup % 10) == 0) result = "Ten";  
  68.             }  
  69.             if (rup > 9 && rup < 20)  
  70.             {  
  71.                 if (rup == 11) result = "Eleven";  
  72.                 if (rup == 12) result = "Twelve";  
  73.                 if (rup == 13) result = "Thirteen";  
  74.                 if (rup == 14) result = "Forteen";  
  75.                 if (rup == 15) result = "Fifteen";  
  76.                 if (rup == 16) result = "Sixteen";  
  77.                 if (rup == 17) result = "Seventeen";  
  78.                 if (rup == 18) result = "Eighteen";  
  79.                 if (rup == 19) result = "Nineteen";  
  80.             }  
  81.             if (rup > 20 && (rup / 10) == 2 && (rup % 10) == 0) result = "Twenty";  
  82.             if (rup > 20 && (rup / 10) == 3 && (rup % 10) == 0) result = "Thirty";  
  83.             if (rup > 20 && (rup / 10) == 4 && (rup % 10) == 0) result = "Forty";  
  84.             if (rup > 20 && (rup / 10) == 5 && (rup % 10) == 0) result = "Fifty";  
  85.             if (rup > 20 && (rup / 10) == 6 && (rup % 10) == 0) result = "Sixty";  
  86.             if (rup > 20 && (rup / 10) == 7 && (rup % 10) == 0) result = "Seventy";  
  87.             if (rup > 20 && (rup / 10) == 8 && (rup % 10) == 0) result = "Eighty";  
  88.             if (rup > 20 && (rup / 10) == 9 && (rup % 10) == 0) result = "Ninty";  
  89.   
  90.             if (rup > 20 && (rup / 10) == 2 && (rup % 10) != 0)  
  91.             {  
  92.                 if ((rup % 10) == 1) result = "Twenty One";  
  93.                 if ((rup % 10) == 2) result = "Twenty Two";  
  94.                 if ((rup % 10) == 3) result = "Twenty Three";  
  95.                 if ((rup % 10) == 4) result = "Twenty Four";  
  96.                 if ((rup % 10) == 5) result = "Twenty Five";  
  97.                 if ((rup % 10) == 6) result = "Twenty Six";  
  98.                 if ((rup % 10) == 7) result = "Twenty Seven";  
  99.                 if ((rup % 10) == 8) result = "Twenty Eight";  
  100.                 if ((rup % 10) == 9) result = "Twenty Nine";  
  101.             }  
  102.             if (rup > 20 && (rup / 10) == 3 && (rup % 10) != 0)  
  103.             {  
  104.                 if ((rup % 10) == 1) result = "Thirty One";  
  105.                 if ((rup % 10) == 2) result = "Thirty Two";  
  106.                 if ((rup % 10) == 3) result = "Thirty Three";  
  107.                 if ((rup % 10) == 4) result = "Thirty Four";  
  108.                 if ((rup % 10) == 5) result = "Thirty Five";  
  109.                 if ((rup % 10) == 6) result = "Thirty Six";  
  110.                 if ((rup % 10) == 7) result = "Thirty Seven";  
  111.                 if ((rup % 10) == 8) result = "Thirty Eight";  
  112.                 if ((rup % 10) == 9) result = "Thirty Nine";  
  113.             }  
  114.             if (rup > 20 && (rup / 10) == 4 && (rup % 10) != 0)  
  115.             {  
  116.                 if ((rup % 10) == 1) result = "Forty One";  
  117.                 if ((rup % 10) == 2) result = "Forty Two";  
  118.                 if ((rup % 10) == 3) result = "Forty Three";  
  119.                 if ((rup % 10) == 4) result = "Forty Four";  
  120.                 if ((rup % 10) == 5) result = "Forty Five";  
  121.                 if ((rup % 10) == 6) result = "Forty Six";  
  122.                 if ((rup % 10) == 7) result = "Forty Seven";  
  123.                 if ((rup % 10) == 8) result = "Forty Eight";  
  124.                 if ((rup % 10) == 9) result = "Forty Nine";  
  125.             }  
  126.             if (rup > 20 && (rup / 10) == 5 && (rup % 10) != 0)  
  127.             {  
  128.                 if ((rup % 10) == 1) result = "Fifty One";  
  129.                 if ((rup % 10) == 2) result = "Fifty Two";  
  130.                 if ((rup % 10) == 3) result = "Fifty Three";  
  131.                 if ((rup % 10) == 4) result = "Fifty Four";  
  132.                 if ((rup % 10) == 5) result = "Fifty Five";  
  133.                 if ((rup % 10) == 6) result = "Fifty Six";  
  134.                 if ((rup % 10) == 7) result = "Fifty Seven";  
  135.                 if ((rup % 10) == 8) result = "Fifty Eight";  
  136.                 if ((rup % 10) == 9) result = "Fifty Nine";  
  137.             }  
  138.             if (rup > 20 && (rup / 10) == 6 && (rup % 10) != 0)  
  139.             {  
  140.                 if ((rup % 10) == 1) result = "Sixty One";  
  141.                 if ((rup % 10) == 2) result = "Sixty Two";  
  142.                 if ((rup % 10) == 3) result = "Sixty Three";  
  143.                 if ((rup % 10) == 4) result = "Sixty Four";  
  144.                 if ((rup % 10) == 5) result = "Sixty Five";  
  145.                 if ((rup % 10) == 6) result = "Sixty Six";  
  146.                 if ((rup % 10) == 7) result = "Sixty Seven";  
  147.                 if ((rup % 10) == 8) result = "Sixty Eight";  
  148.                 if ((rup % 10) == 9) result = "Sixty Nine";  
  149.             }  
  150.             if (rup > 20 && (rup / 10) == 7 && (rup % 10) != 0)  
  151.             {  
  152.                 if ((rup % 10) == 1) result = "Seventy One";  
  153.                 if ((rup % 10) == 2) result = "Seventy Two";  
  154.                 if ((rup % 10) == 3) result = "Seventy Three";  
  155.                 if ((rup % 10) == 4) result = "Seventy Four";  
  156.                 if ((rup % 10) == 5) result = "Seventy Five";  
  157.                 if ((rup % 10) == 6) result = "Seventy Six";  
  158.                 if ((rup % 10) == 7) result = "Seventy Seven";  
  159.                 if ((rup % 10) == 8) result = "Seventy Eight";  
  160.                 if ((rup % 10) == 9) result = "Seventy Nine";  
  161.             }  
  162.             if (rup > 20 && (rup / 10) == 8 && (rup % 10) != 0)  
  163.             {  
  164.                 if ((rup % 10) == 1) result = "Eighty One";  
  165.                 if ((rup % 10) == 2) result = "Eighty Two";  
  166.                 if ((rup % 10) == 3) result = "Eighty Three";  
  167.                 if ((rup % 10) == 4) result = "Eighty Four";  
  168.                 if ((rup % 10) == 5) result = "Eighty Five";  
  169.                 if ((rup % 10) == 6) result = "Eighty Six";  
  170.                 if ((rup % 10) == 7) result = "Eighty Seven";  
  171.                 if ((rup % 10) == 8) result = "Eighty Eight";  
  172.                 if ((rup % 10) == 9) result = "Eighty Nine";  
  173.             }  
  174.             if (rup > 20 && (rup / 10) == 9 && (rup % 10) != 0)  
  175.             {  
  176.                 if ((rup % 10) == 1) result = "Ninty One";  
  177.                 if ((rup % 10) == 2) result = "Ninty Two";  
  178.                 if ((rup % 10) == 3) result = "Ninty Three";  
  179.                 if ((rup % 10) == 4) result = "Ninty Four";  
  180.                 if ((rup % 10) == 5) result = "Ninty Five";  
  181.                 if ((rup % 10) == 6) result = "Ninty Six";  
  182.                 if ((rup % 10) == 7) result = "Ninty Seven";  
  183.                 if ((rup % 10) == 8) result = "Ninty Eight";  
  184.                 if ((rup % 10) == 9) result = "Ninty Nine";  
  185.             }  
  186.             return result;  
  187.         }  
  188.       
  189.     }  
  190. }  

Answers (7)