Formatting a currency value

4 posts, 0 answers
  1. Kathy
    Kathy avatar
    35 posts
    Member since:
    Sep 2010

    Posted 03 Oct 2010 Link to this post

    I have a column that will show dollar amounts in the millions.  I want the data to display with comma separators.  The underlying data is stored as an integer ( although this is not cast in stone and can be made to be decimal if need be ).  If I use a GridMaskedColumn, I get the thousands separators, but it gives an error on the input type when I try to save it.  I'm using the autogenerated edit forms for this.  The mask is "###,###,###".  So I guess I need to get the data and convert it back to integer to save it.  Where do I go to cast this back to an integer?  Thanks.
  2. Andy Green
    Andy Green avatar
    342 posts
    Member since:
    Aug 2008

    Posted 04 Oct 2010 Link to this post

    You dont say where your data is coming from,

    Assuming a SQL Server can you not use the SQL comman CONVERT and return the data already formatted?

    If changing datatype you also might consider changing  to Money rather than Decimal as it has a higer internal accurancy, although not needed if you are sure to be only using integers.

    Andy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kathy
    Kathy avatar
    35 posts
    Member since:
    Sep 2010

    Posted 05 Oct 2010 Link to this post

    I can use a masked column for the input and I'm assuming in the InsertCommand that I could take the value entered in the radgrid and remove the commas so that it can be stored in the db.  How would I go about locating that one particular field and removing the commas from it so that it's the correct datatype?
  5. Marin
    Admin
    Marin avatar
    1043 posts

    Posted 06 Oct 2010 Link to this post

    Hi Kathy,

    You may try setting the DataType property of the relevant column (i.e the GridMaskedColumn) to the correct type of the data. Or a better option is to use GridNumericColumn or GridBoundColumn and set the pattern for the number using the DataFormatString property. You may find additional information about different column types in this help topic and this live demo. If you still need to get the value from a certain items in the code-behind it can be done as shown in the following article.

    Kind regards,
    Marin
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
Back to Top