Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Таблица с примером https://docs.google.com/spreadsheets/d/1c68bh_y0PV6FN-h1u6N-NJteb4-9b359I4nqWAJw7NU/edit#gid=0
- ✅ Канал о Таблицах: https://t.me/google_sheets
- ✅ Чат: https://t.me/google_spreadsheets_chat
- ✅ Оглавление канала: https://goo.gl/HdS2qn
- */
- function words(input) {
- var a, b, c, d, e, f, output, outputA, outputB, outputC, outputD, outputE, outputF;
- var ones = ['', 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX', 'SEVEN', 'EIGHT', 'NINE'];
- if (input === 0) { // Zero
- output = "ZERO DOLLARS";
- } else if (input == 1) { // One
- output = "ONE DOLLAR ONLY";
- } else { // More than one
- input1 = Math.floor(input)
- // Tens
- a = input1 % 100;
- outputA = oneToHundred_(a);
- // Hundreds
- b = Math.floor((input1 % 1000) / 100);
- if (b > 0 && b < 10) {
- outputB = ones[b];
- }
- // Thousands
- c = (Math.floor(input1 / 1000)) % 100;
- outputC = oneToHundred_(c);
- // Millions
- d = (Math.floor(input1 / 100000)) % 100;
- outputD = oneToHundred_(d);
- // Billions
- e = (Math.floor(input1 / 10000000)) % 100;
- outputE = oneToHundred_(e);
- // Cents
- f = Math.round((input - input1) * 100);
- outputF = f;
- output = "USD";
- if (a > 0) {
- output = outputA;
- }
- if (b > 0) {
- output = outputB + " HUNDRED " + output;
- }
- if (c > 0) {
- output = outputC + " THOUSAND " + output;
- }
- if (d > 0) {
- output = outputD + " MILLION " + output;
- }
- if (e > 0) {
- output = outputE + " BILLION " + output;
- }
- output = output + " DOLLARS";
- if (f > 0) {
- output = output + " AND " + outputF + " CENTS"
- }
- }
- return output;
- }
- function oneToHundred_(num) {
- var outNum;
- var ones = ['', 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX', 'SEVEN', 'EIGHT', 'NINE'];
- var teens = ['TEN', 'ELEVEN', 'TWELVE', 'THIRTEEN', 'FOURTEEN', 'FIFTEEN', 'SIXTEEN', 'SEVENTEEN', 'EIGHTEEN', 'NINETEEN'];
- var tens = ['', '', 'TWENTY', 'THIRTY', 'FORTY', 'FIFTY', 'SIXTY', 'SEVENTY', 'EIGHTY', 'NINETY'];
- if (num >= 0 && num < 10) { // 1 to 9
- outNum = ones[num]; // ones
- } else if (num > 9 && num < 20) { // 10 to 19
- outNum = teens[(num % 10)]; // teens
- } else if (num > 19 && num < 100) { // 20 to 100
- outNum = tens[Math.floor(num / 10)]; // tens
- if (num % 10 > 0) {
- outNum = outNum + " " + ones[num % 10]; // tens + ones
- }
- }
- return outNum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement