Currency Value

4 posts, 0 answers
  1. Yunuen Sanchez
    Yunuen Sanchez avatar
    31 posts
    Member since:
    Aug 2009

    Posted 01 Dec 2015 Link to this post

    Hello, 

    I would like to capture a currency value on a text field, I want the user to see it in a $ XXX.XX format. I tried to format the number using a Formatter but it didn't work:

    var moneyFormatter = new NSNumberFormatter ();
    moneyFormatter.NumberStyle = NSNumberFormatterStyle.Currency;

    TKEntityProperty montoCobradoProperty = this.dataSource["MontoCobrado"];
    montoCobradoProperty.HintText = "Monto Cobrado";
    montoCobradoProperty.EditorClass = new Class (typeof(TKDataFormNumberEditor));
    montoCobradoProperty.Validators = new NSObject[] { new NumberValidator() };
    montoCobradoProperty.Formatter = moneyFormatter;

     

    What am I doing wrong? is there any other way to achieve this request?

     

    Thanks

  2. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 03 Dec 2015 Link to this post

    Hi, Yunuen,

    Thank you for writing.

    The way you are trying to format the text field value is correct. I can confirm that the described issue appears in TKDataForm. It will be addressed in one of our future releases. I logged it in our feedback portal where you can follow its status. I also updated your Telerik points for reporting this issue.
    If you need to display the property's value in currency format in read only mode you can subclass TKDataFormNumberEditor and override its Update() method to format the value. Please consider the code snippet below:
    public class MyNumberEditor : TKDataFormNumberEditor
    {
        NSNumberFormatter formatter = new NSNumberFormatter ();
     
        public MyNumberEditor () : base()
        {
            formatter.NumberStyle = NSNumberFormatterStyle.Currency;
        }
                 
        public override void Update ()
        {
            base.Update ();
            this.TextField.Text = formatter.StringFromNumber((NSNumber)this.Property.ValueCandidate);
        }
    }

    If you have further questions, do not hesitate to contact us.

    Regards,
    Adrian
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Yunuen Sanchez
    Yunuen Sanchez avatar
    31 posts
    Member since:
    Aug 2009

    Posted 03 Dec 2015 in reply to Adrian Link to this post

    Thanks for the update Adrian! The code is working great.
  5. Adrian
    Admin
    Adrian avatar
    167 posts

    Posted 04 Dec 2015 Link to this post

    Hello, Yunuen,

    I am glad that I could help. 

    Regards,
    Adrian
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner