Announcement

Collapse
No announcement yet.

Format for Currency

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    You can do your own custom formatting on the fly although it does take some work. I don't have time to do it all the way right now, but here is something to work off of. Paste this into the On Key event of an Input field:

    Code:
    -- Get the current input...
    local strInput = Input.GetText(this);
    local tbSel = Input.GetSelection(this);
    
    local strOutput = "";
    
    local nStringLength = String.Length(strInput);
    local bPeriodFound = false;
    
    -- Pick out all of the numerical data
    for i = 1, nStringLength do
    	local strChar = String.Mid(strInput,i,1);
    	if(strChar == ".")then
    		if not bPeriodFound then
    			bPeriodFound = true;
    			strOutput = strOutput..strChar;
    		end
    	end
    	if ((strChar == "0") or (strChar == "1")
    		or (strChar == "2") or (strChar == "3")
    		or (strChar == "4") or (strChar == "5")
    		or (strChar == "6") or (strChar == "7")
    		or (strChar == "8") or (strChar == "9")) then
    		strOutput = strOutput..strChar;
    	end
    end
    
    strOutput = "$"..strOutput;
    
    Input.SetText(this,strOutput);
    
    -- A little hack to set selection to the end
    Input.SetSelection(this,1,-1);
    Input.SetSelection(this,-1,1);
    Maybe you or someone else can pick up and finish it off.

    Comment


    • #32
      Windows has a built function in KERNEL32.DLL called GetCurrencyFormat. Here is a page that talks about it



      I have been trying to figure out how to make a successful dll call to this function to have it return information based on the system local. As of yet, I have been unsuccessful. I will keep working on it and if I come up with anything I will let you know.
      TJ-Tigger
      "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
      "Draco dormiens nunquam titillandus."
      Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

      Comment


      • #33
        [trumpet blast]TADA[/trumpet blast]

        This just in from Worm. A project that contains another fantastic WormWare DLL. This DLL uses the GetCurrency function and returns the value in the local of the users system. Take a look
        Attached Files
        TJ-Tigger
        "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
        "Draco dormiens nunquam titillandus."
        Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

        Comment


        • #34
          Ohhh... Ahhh... nice!

          I'm uploading this example for sure! (credit to you both).

          Thanks guys!
          Intrigued

          Comment


          • #35
            I have also found it helpful to use the LUA code string.format. I have an app I am working on right now for tracking sales and am trying to display prices but if the price is 150.00 when I display that as a string I get 150.

            Here is what I have done to force it to display the two zeros.

            string.format("%.2f", "150.00") -- This formats the number to have two decimal places.

            I tried the Math.Round to two decimal places but if they were both zero, they woud disappear when displayed. But the string.format command above works well.

            Tigg
            TJ-Tigger
            "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
            "Draco dormiens nunquam titillandus."
            Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

            Comment


            • #36
              Thx all of you, especially Worm (a new treasure for my DWL directory) and to eddie_d_2000 for starting this thread.

              The FormatCurrency.dll results from Norway:
              Keypad entry: 123456,78 = UNKNOWN
              But with the dot (123456.78) = kr 123 456,78
              (and that's not difficult to change = Registry sDecimal)

              Don't forget Brett's Tip: Changing the Locale

              Comment


              • #37
                I am happy to help,

                Comment

                Working...
                X