Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to allow user to enter/edit parameter as currency

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

    How to allow user to enter/edit parameter as currency

    I would like to allow the user of my strategy to enter/edit a parameter that is a currency. For example, lets say the following were displayed in my parameters list:
    MaxDailyLoss $000.00
    If 400 (with or without $) were typed and tab or return key pressed $400.00 would be displayed and a double variable in my code would be filled with 400.00. I can think of several ways this could be done. Just looking for the best or NT friendly way.

    #2
    Originally posted by bernie_c View Post
    I would like to allow the user of my strategy to enter/edit a parameter that is a currency. For example, lets say the following were displayed in my parameters list:
    MaxDailyLoss $000.00
    If 400 (with or without $) were typed and tab or return key pressed $400.00 would be displayed and a double variable in my code would be filled with 400.00. I can think of several ways this could be done. Just looking for the best or NT friendly way.
    Parse a string into a double, but display the Property as the string?

    Comment


      #3
      Hello,

      Thank you for the question.

      If you absolutely need the $ in the field where you type the value, I would agree with koganam on parsing a string into a double.

      Otherwise another solution would be to put the $ in the parameter name, here is a simple example parameter:

      Code:
      private double maxDailyLoss;
      		
      [Description("")]
      [GridCategory("Parameters")]
      [Gui.Design.DisplayName("MaxDailyLoss $")]
      public double MaxDailyLoss
      {
      	get{ return maxDailyLoss;} set{ Math.Max(1, value);}
      }
      I look forward to being of further assistance.

      Comment


        #4
        Koganam,
        This code snippet is what I tried before starting this thread. I was certain it would work, however, the quoted exception is thrown. Is this what you meant by "parse"?
        Code:
        [Description( "" )]
        [GridCategory("c Parameters")]
        [Gui.Design.DisplayName ("       Dollars")]
        public string Dollar_str
        {
            get { return dollar_str; }
            set { 			
                             dollar_num   = Double.Parse( value );
        		     dollar_str	= dollar_num.ToString(); 
        	  }	
        }
        **NT** Error on getting/setting property 'Dollar_str' for strategy 'bcSm/296c35a0a40e426db1b2c74ab9323fb0': Exception has been thrown by the target of an invocation.

        Comment


          #5
          Originally posted by bernie_c View Post
          Koganam,
          This code snippet is what I tried before starting this thread. I was certain it would work, however, the quoted exception is thrown. Is this what you meant by "parse"?
          Code:
          [Description( "" )]
          [GridCategory("c Parameters")]
          [Gui.Design.DisplayName ("       Dollars")]
          public string Dollar_str
          {
              get { return dollar_str; }
              set { 			
                               dollar_num   = Double.Parse( value );
          		     dollar_str	= dollar_num.ToString(); 
          	  }	
          }
          That depends on whether the currency symbol is a part of your string. In which case, you have to specify "NumberStyles".

          Comment


            #6
            Here is what worked:
            Code:
            get { return dollar_str; }
            set { 			
            	dollar_num = Double.Parse( value, NumberStyles.Number | NumberStyles.AllowCurrencySymbol );
            				
            	dollar_str	 = dollar_num.ToString( "C", new System.Globalization.CultureInfo("en-US") );
                   }
            I had tried using NumberStyles earlier, but was getting compile errors because my using statements were not right. All is good now though.

            Thanks again Koganam.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            558 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X