Skip to content

Commit

Permalink
number to french by mistral large 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ToonTalk committed Aug 2, 2024
1 parent daf2a5b commit aab3aad
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
18 changes: 18 additions & 0 deletions apps/number to french by Mistral Large 2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number to French Converter</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Number to French Converter</h1>
<input type="text" id="numberInput" placeholder="Enter a number">
<button onclick="convertToFrench()">Convert</button>
<p id="result"></p>
</div>
<script src="script.js"></script>
</body>
</html>
53 changes: 53 additions & 0 deletions apps/number to french by Mistral Large 2/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function convertToFrench() {
const numberInput = document.getElementById('numberInput').value;
let number;

try {
number = BigInt(numberInput);
} catch (e) {
document.getElementById('result').textContent = 'Please enter a valid number.';
return;
}

const resultElement = document.getElementById('result');
const frenchWords = convertNumberToFrench(number);
resultElement.textContent = `French: ${frenchWords}`;
}

function convertNumberToFrench(number) {
const units = ['zéro', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf'];
const teens = ['dix', 'onze', 'douze', 'treize', 'quatorze', 'quinze', 'seize', 'dix-sept', 'dix-huit', 'dix-neuf'];
const tens = ['', 'dix', 'vingt', 'trente', 'quarante', 'cinquante', 'soixante', 'soixante', 'quatre-vingt', 'quatre-vingt'];
const specialTens = ['soixante-dix', 'quatre-vingt-dix'];

if (number === 0n) return units[0];

let result = '';
let numStr = number.toString();

if (numStr.length > 3) {
result += convertNumberToFrench(BigInt(numStr.slice(0, -3))) + ' mille ';
numStr = numStr.slice(-3);
}

if (numStr.length === 3) {
if (numStr[0] !== '0') {
result += units[Number(numStr[0])] + ' cent ';
}
numStr = numStr.slice(1);
}

if (numStr.length === 2) {
if (numStr[0] === '1') {
result += teens[Number(numStr[1])] + ' ';
} else if (numStr[0] === '7' || numStr[0] === '9') {
result += specialTens[Number(numStr[0]) - 7] + '-' + units[Number(numStr[1])] + ' ';
} else {
result += tens[Number(numStr[0])] + ' ' + units[Number(numStr[1])] + ' ';
}
} else if (numStr.length === 1) {
result += units[Number(numStr[0])] + ' ';
}

return result.trim();
}
35 changes: 35 additions & 0 deletions apps/number to french by Mistral Large 2/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
background-color: #f0f0f0;
}

.container {
text-align: center;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

input {
padding: 10px;
margin: 10px;
font-size: 16px;
}

button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
}

p {
margin-top: 20px;
font-size: 18px;
color: #333;
}

0 comments on commit aab3aad

Please sign in to comment.