# Ember-data store my attr('number') as a string!? Why?

**URL:** <https://discuss.emberjs.com/t/ember-data-store-my-attr-number-as-a-string-why/11904>\
**Category:** Ember Data\
**Created:** [November 9, 2016, 5:51pm UTC](https://discuss.emberjs.com/t/ember-data-store-my-attr-number-as-a-string-why/11904 "2016-11-09T17:51:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Myrdhin](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/myrdhin/32/16107_2.png) [@Myrdhin](https://discuss.emberjs.com/u/Myrdhin)\
**Post date:** [November 9, 2016, 5:51pm UTC](https://discuss.emberjs.com/t/ember-data-store-my-attr-number-as-a-string-why/11904/1 "2016-11-09T17:51:56Z")

</div>

Hello,

I define this model:

```
import DS from 'ember-data';

export default DS.Model.extend({
    nb: DS.attr('number')
});

```

And, in my template, i use:

`{{input name="mynb" value=(mut model.nb)}}`

But when i use `nb` in my controller after changed its value with this input, `nb` become a string?! I thought ember-data cast it to a number before store it (_and not only when i send my modified model to my backend server_). No?

Will we have to create an action in the controller or a Computed Property in the model to perform this type casting 😥?

Thanks for your help,

---

<div class="post-metadata">

**Author:** ![lightblade](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/lightblade/32/15632_2.png) [@lightblade](https://discuss.emberjs.com/u/lightblade)\
**Post date:** [November 10, 2016, 3:46am UTC](https://discuss.emberjs.com/t/ember-data-store-my-attr-number-as-a-string-why/11904/2 "2016-11-10T03:46:25Z")

</div>

Um, because native input tag stores it string?

Also, that type you give to DS.attr only get looked at by serializer. It does the conversion when it get send to the server, but not before. If you have a custom serializer, it’s possible this step is skipped altogether.

---

<div class="post-metadata">

**Author:** ![nightire](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nightire/32/14788_2.png) [@nightire](https://discuss.emberjs.com/u/nightire)\
**Post date:** [November 10, 2016, 4:28am UTC](https://discuss.emberjs.com/t/ember-data-store-my-attr-number-as-a-string-why/11904/3 "2016-11-10T04:28:56Z")

</div>

Because input will casting this value to strings, it always does even if you specify `type=number`, no need to worry it to much because ember data serializer will handle that for you, but if you need to do mathematic calculation in other layer, components for example, you need to cast it back to number explicitly.

---

<div class="post-metadata">

**Author:** ![Myrdhin](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/myrdhin/32/16107_2.png) [@Myrdhin](https://discuss.emberjs.com/u/Myrdhin)\
**Post date:** [November 10, 2016, 7:47am UTC](https://discuss.emberjs.com/t/ember-data-store-my-attr-number-as-a-string-why/11904/4 "2016-11-10T07:47:38Z")

</div>

Thank you.

I’s actually what I understood 😕 . Ember-data does not auto cast the attributes when store the data. So I created a component `{{numeric-field}}` to be sure to return a `Number`.

see [Number attributes don’t convert values properly when used with input helpers #11209](https://github.com/emberjs/ember.js/issues/11209)
