Advertisement
halleman19

money separator // not regex

Dec 9th, 2024
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Xml;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Program
  7. {
  8.     public static void Main()
  9.     {
  10.         string numb;
  11.  
  12.         do
  13.         {
  14.  
  15.             Console.WriteLine("Enter input: ");
  16.  
  17.             numb = Console.ReadLine();
  18.  
  19.             Console.WriteLine("Format input: " + sepMoney(int.Parse(numb)));
  20.             Console.WriteLine();
  21.             Console.WriteLine();
  22.         }
  23.         while (numb != "666");
  24.     }
  25.  
  26.     private static string sepMoney(int numb)
  27.     {
  28.         char sepChar = ',';
  29.         string money = "";
  30.  
  31.         int sepAmount = 1000;
  32.  
  33.         while ((numb % sepAmount) > 100)
  34.         {
  35.             money = string.Format("{1}{2}{0}", money, numb % sepAmount, sepChar);
  36.             numb = numb / sepAmount;
  37.         }
  38.  
  39.         if (numb > 0)
  40.             money = string.Format("{0}{2}{1}", numb, money, sepChar);
  41.  
  42.         if (money[money.Length - 1] == sepChar)
  43.             money = money.Substring(0, money.Length - 1);
  44.  
  45.         return money;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement