Convert English Number To Nepali Number Using PHP, C#, Java, Javascript, Python

 1. Convert English Number To Nepali Number Using PHP

We can replace english number to nepali number by using str_replace() php built in function.
The str_replace() function replaces some characters with some other characters in a string.
Example:

    <?php
    function en_to_np_number_converter($number){
        $en_number = array(
            "0",
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7",
            "8",
            "9"
        );
        $np_number = array(
            "०",
            "१",
            "२",
            "३",
            "४",
            "५",
            "६",
            "७",
            "८",
            "९"
        );
        return str_replace($en_number, $np_number, $number);
    }
    echo en_to_np_number_converter(100);
  ?>


2. Convert English Number To Nepali Number Using c#

We can replace english number to nepali number by using Replace()  C# built in function.
It returns a new string in which all occurrences of a specified Unicode character or String in the current string are replaced with another specified Unicode character or String. We can replace multiple substrings at once using replace() method chaining.
Example:

using System;
                   
public class Program
{
    public static void Main()
    {
        Console.WriteLine(EnglishToNepaliNumber("1234"));
    }
   
     public static string EnglishToNepaliNumber(string input)
    {
   
            return input.Replace('0', '०')
                    .Replace('1', '१')
                    .Replace('2', '२')
                    .Replace('3', '३')
                    .Replace('4', '४')
                    .Replace('5', '५')
                    .Replace('6', '६')
                    .Replace('7', '७')
                    .Replace('8', '८')
                    .Replace('9', '९');
    }
}

3. Convert English Number To Nepali Number Using Java

We can replace english number to nepali number by using replace() java built in function.
The the predefined java replace() function searches a string for a specified character, and returns a new string where the specified character(s) are replaced.We can replace multiple substrings at once using replace() method chaining.

Example


    public class Main
    {
        public static void main(String[] args) {
            System.out.println(ConvertNumerals("1234"));
        }
        public static String ConvertNumerals(
            String input)
        {
       
                return input.replace('0', '०')
                        .replace('1', '१')
                        .replace('2', '२')
                        .replace('3', '३')
                        .replace('4', '४')
                        .replace('5', '५')
                        .replace('6', '६')
                        .replace('7', '७')
                        .replace('8', '८')
                        .replace('9', '९');
        }
    }


4. Convert English Number To Nepali Number Using Javscript

We can replace english number to nepali number by using map() javascript built in function.

Example

   
    <script>
        function englishToNepali(number) {

        let nepaliNumberss = ['०', '१', '२', '३', '४', '५', '६', '७', '८', '९'];    
        const numberToConvert = number.toString().split('');

        let result = numberToConvert.map((num, i) => {
        return nepaliNumberss[i, num];
        });

        return result.join('');
    }
    console.log(englishToNepali(12345678910));
    </script>
 

5. Convert English Number To Nepali Number Using Python

We can replace english number to nepali number by using replace() python built in function.
We can replace multiple substrings at once using replace() method chaining.
Example


    def converToNepali(input):
        return input.replace('0','०')
        .replace('1','१')
        .replace('2','२')
        .replace('3','३')
        .replace('4','४')
        .replace('5','५')
        .replace('6','६')
        .replace('7','७')
        .replace('8','८')
        .replace('9','९')
                           
    print(converToNepali('123546'))
           

           




Reactions

Post a Comment

0 Comments