Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 31529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:37:10+00:00 2026-05-10T13:37:10+00:00

Is there an efficient method of converting an integer into the written numbers, for

  • 0

Is there an efficient method of converting an integer into the written numbers, for example:

string Written = IntegerToWritten(21); 

would return ‘Twenty One’.

Is there any way of doing this that doesn’t involve a massive look-up table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T13:37:11+00:00Added an answer on May 10, 2026 at 1:37 pm

    This should work reasonably well:

    public static class HumanFriendlyInteger {     static string[] ones = new string[] { '', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine' };     static string[] teens = new string[] { 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen' };     static string[] tens = new string[] { 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety' };     static string[] thousandsGroups = { '', ' Thousand', ' Million', ' Billion' };      private static string FriendlyInteger(int n, string leftDigits, int thousands)     {         if (n == 0)         {             return leftDigits;         }          string friendlyInt = leftDigits;          if (friendlyInt.Length > 0)         {             friendlyInt += ' ';         }          if (n < 10)         {             friendlyInt += ones[n];         }         else if (n < 20)         {             friendlyInt += teens[n - 10];         }         else if (n < 100)         {             friendlyInt += FriendlyInteger(n % 10, tens[n / 10 - 2], 0);         }         else if (n < 1000)         {             friendlyInt += FriendlyInteger(n % 100, (ones[n / 100] + ' Hundred'), 0);         }         else         {             friendlyInt += FriendlyInteger(n % 1000, FriendlyInteger(n / 1000, '', thousands+1), 0);             if (n % 1000 == 0)             {                 return friendlyInt;             }         }          return friendlyInt + thousandsGroups[thousands];     }      public static string IntegerToWritten(int n)     {         if (n == 0)         {             return 'Zero';         }         else if (n < 0)         {             return 'Negative ' + IntegerToWritten(-n);         }          return FriendlyInteger(n, '', 0);     } } 

    (Edited to fix a bug w/ million, billion, etc.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a more efficient way to clamp real numbers than using if statements
is there a smart and efficient way to add logs to all REST method
Is there an efficient way of detecting if a jpeg file is corrupted? Background
Is there an efficient way to tell if a DOM element (in an HTML
Is there an efficient way to store the compiled regexes (compiled via regcomp(), PCRE)
Is there an efficient way to create a file with a given size in
Is there an efficient way to take a subset of a C# array and
SQL Experts, Is there an efficient way to group runs of data together using
Is there a more efficient way to convert an HTMLCollection to an Array, other
Is there an algorithm that is more time efficient than O(n^2) for detecting cycles

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.