In french , 1(one) is said as un
, what i want to do is as soon as i want to convert a number to a string . For example,if the number(integer) is 1
then the result would be un
, how to achieve this ?
Asked
Active
Viewed 1,105 times
-4

Software Dev
- 5,368
- 5
- 22
- 45

InfoEtud
- 1
- 2
-
Please be more specific. WHat type of number. What is the required format. – Edwin Bentveld Mar 31 '18 at 12:29
-
`1234` , can this be converted to `Hello` ?? How can u expect a number to become a word and even FRENCH!! ...However , to get an integer as string just use `myinteger.ToString` – Software Dev Mar 31 '18 at 12:29
-
@zack raiyan hope it is 1 = "one" (eng) = "un" (french) – Eduard Abliazimov Mar 31 '18 at 12:31
-
3try to look https://stackoverflow.com/questions/554314/how-can-i-convert-an-integer-into-its-verbal-representation – Eduard Abliazimov Mar 31 '18 at 12:35
-
please approve my edit to make it clear for others to understand – Software Dev Mar 31 '18 at 12:36
-
To be more specific i want the format to fill in a check. For example: 1200 will be converted as "Mille deux cent" – InfoEtud Mar 31 '18 at 12:38
-
`if (myint ==1) { string result = "un" }` – Software Dev Mar 31 '18 at 12:40
-
@zackraiyan but when i have big integers how to do? – InfoEtud Mar 31 '18 at 12:41
-
`if (myint ==1200) { string result = "Mille deux cent" }` – Software Dev Mar 31 '18 at 12:44
-
I wnat that that will be done automatically not to a specific numbers! – InfoEtud Mar 31 '18 at 12:45
-
It can't happen automatically, what you can do is create a text file for all the number(in frech),read it and store it in a list, and then use the list :) – Software Dev Mar 31 '18 at 12:54
2 Answers
0
A more specific question would be more helpful. But I'm going to take a guess you mean something like the following. Unfortunately there's no built-in special formatting tricks to handle the singular case.
string text = number == 1 ? "un" : number.ToString();
You might also be interested in a formatting library like Pluralizer: http://www.jasonq.com/blog/2011/introduction-to-a-string-pluralizer-for-net

Peter Aylett
- 750
- 3
- 8
0
I implemented this in English, as my French isn't perfect.
using System;
using System.Collections.Generic;
namespace LanguageNumberConverter
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number: ");
var input = int.Parse(Console.ReadLine());
var result = NumberConverter(input);
Console.WriteLine($"The number {input} = {result}.");
}
static string NumberConverter(int number)
{
var resultWords = new List<string>();
var chars = number.ToString().ToCharArray();
var largeCount = (chars.Length - 1) / 3;
for (var l = largeCount; l >= 0; l--)
{
var searchRange = chars.Length - (l * 3);
var digitStart = searchRange - 3 > 0 ? searchRange - 3 : 0;
var digitsInLarge = l == largeCount ? chars.Length % 3 : 3;
var teenFound = false;
//Hundreds
if (digitsInLarge > 2)
{
var hunDigit = int.Parse(chars[digitStart].ToString());
resultWords.Add(Ones[hunDigit]);
resultWords.Add("Hundred");
}
//Tens
if (digitsInLarge > 1)
{
var tenDigit = int.Parse(chars[digitStart + digitsInLarge - 2].ToString());
if (tenDigit == 1)
{
teenFound = true;
var teenDigit = (tenDigit * 10) + int.Parse(chars[digitStart + digitsInLarge - 1].ToString());
resultWords.Add(Ones[teenDigit]);
}
else
{
resultWords.Add(Tens[tenDigit]);
}
}
//Ones
if (!teenFound)
{
var oneDigit = int.Parse(chars[digitStart + digitsInLarge - 1].ToString());
resultWords.Add(Ones[oneDigit]);
}
//Large
if (l > 0)
{
var unit = Large[l];
resultWords.Add(unit);
}
}
var result = "";
foreach (var word in resultWords)
{
result += word + " ";
}
return result.Trim();
}
static string[] Ones =
{
"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen",
"Eighteen", "Nineteen"
};
static string[] Tens =
{
"Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy",
"Eighty", "Ninety"
};
static string[] Large =
{
"Zero", "Thousand", "Million", "Billion", "Trillion"
};
}
}

Tim
- 2,089
- 1
- 12
- 21