Simple comparing throw wrong result Vue










-1















I've got 2 components in a modal.



The first:



 <v-text-field
label="Limite de faltantes"
type="number"
v-model="lim_faltProd"
></v-text-field>


The second:



 <v-text-field
label="Limite de excedentes"
type="number"
v-model="lim_excProd"
></v-text-field>


My component export:



export default {
props: ['nombre', 'precio', 'lim_falt', 'lim_exc', 'id'],
data ()
return
error: '',
idProd: this.id,
nombreProd: this.nombre,
precioProd: this.precio,
lim_faltProd: this.lim_falt,
lim_excProd: this.lim_exc

,
watch:
nombre ()
this.nombreProd = this.nombre
,
precio ()
this.precioProd = this.precio
,
lim_falt ()
this.lim_faltProd = this.lim_falt
,
lim_exc ()
this.lim_excProd = this.lim_exc
,
id ()
this.idProd = this.id




So when i try to do such a simple thing like




this.lim_faltProd >= this.lim_excProd




It gets crazy.



Look at this, I get




console.log(this.lim_faltProd) // 20



console.log(this.lim_excProd) // 100



console.log(this.lim_faltProd >= this.lim_excProd) // THROWS TRUE!!!!






I'll show it:
I've a function where I do:



 async registrarProducto () 
this.error = this.lim_faltProd > this.lim_excProd



RESULT:



enter image description here










share|improve this question


























    -1















    I've got 2 components in a modal.



    The first:



     <v-text-field
    label="Limite de faltantes"
    type="number"
    v-model="lim_faltProd"
    ></v-text-field>


    The second:



     <v-text-field
    label="Limite de excedentes"
    type="number"
    v-model="lim_excProd"
    ></v-text-field>


    My component export:



    export default {
    props: ['nombre', 'precio', 'lim_falt', 'lim_exc', 'id'],
    data ()
    return
    error: '',
    idProd: this.id,
    nombreProd: this.nombre,
    precioProd: this.precio,
    lim_faltProd: this.lim_falt,
    lim_excProd: this.lim_exc

    ,
    watch:
    nombre ()
    this.nombreProd = this.nombre
    ,
    precio ()
    this.precioProd = this.precio
    ,
    lim_falt ()
    this.lim_faltProd = this.lim_falt
    ,
    lim_exc ()
    this.lim_excProd = this.lim_exc
    ,
    id ()
    this.idProd = this.id




    So when i try to do such a simple thing like




    this.lim_faltProd >= this.lim_excProd




    It gets crazy.



    Look at this, I get




    console.log(this.lim_faltProd) // 20



    console.log(this.lim_excProd) // 100



    console.log(this.lim_faltProd >= this.lim_excProd) // THROWS TRUE!!!!






    I'll show it:
    I've a function where I do:



     async registrarProducto () 
    this.error = this.lim_faltProd > this.lim_excProd



    RESULT:



    enter image description here










    share|improve this question
























      -1












      -1








      -1








      I've got 2 components in a modal.



      The first:



       <v-text-field
      label="Limite de faltantes"
      type="number"
      v-model="lim_faltProd"
      ></v-text-field>


      The second:



       <v-text-field
      label="Limite de excedentes"
      type="number"
      v-model="lim_excProd"
      ></v-text-field>


      My component export:



      export default {
      props: ['nombre', 'precio', 'lim_falt', 'lim_exc', 'id'],
      data ()
      return
      error: '',
      idProd: this.id,
      nombreProd: this.nombre,
      precioProd: this.precio,
      lim_faltProd: this.lim_falt,
      lim_excProd: this.lim_exc

      ,
      watch:
      nombre ()
      this.nombreProd = this.nombre
      ,
      precio ()
      this.precioProd = this.precio
      ,
      lim_falt ()
      this.lim_faltProd = this.lim_falt
      ,
      lim_exc ()
      this.lim_excProd = this.lim_exc
      ,
      id ()
      this.idProd = this.id




      So when i try to do such a simple thing like




      this.lim_faltProd >= this.lim_excProd




      It gets crazy.



      Look at this, I get




      console.log(this.lim_faltProd) // 20



      console.log(this.lim_excProd) // 100



      console.log(this.lim_faltProd >= this.lim_excProd) // THROWS TRUE!!!!






      I'll show it:
      I've a function where I do:



       async registrarProducto () 
      this.error = this.lim_faltProd > this.lim_excProd



      RESULT:



      enter image description here










      share|improve this question














      I've got 2 components in a modal.



      The first:



       <v-text-field
      label="Limite de faltantes"
      type="number"
      v-model="lim_faltProd"
      ></v-text-field>


      The second:



       <v-text-field
      label="Limite de excedentes"
      type="number"
      v-model="lim_excProd"
      ></v-text-field>


      My component export:



      export default {
      props: ['nombre', 'precio', 'lim_falt', 'lim_exc', 'id'],
      data ()
      return
      error: '',
      idProd: this.id,
      nombreProd: this.nombre,
      precioProd: this.precio,
      lim_faltProd: this.lim_falt,
      lim_excProd: this.lim_exc

      ,
      watch:
      nombre ()
      this.nombreProd = this.nombre
      ,
      precio ()
      this.precioProd = this.precio
      ,
      lim_falt ()
      this.lim_faltProd = this.lim_falt
      ,
      lim_exc ()
      this.lim_excProd = this.lim_exc
      ,
      id ()
      this.idProd = this.id




      So when i try to do such a simple thing like




      this.lim_faltProd >= this.lim_excProd




      It gets crazy.



      Look at this, I get




      console.log(this.lim_faltProd) // 20



      console.log(this.lim_excProd) // 100



      console.log(this.lim_faltProd >= this.lim_excProd) // THROWS TRUE!!!!






      I'll show it:
      I've a function where I do:



       async registrarProducto () 
      this.error = this.lim_faltProd > this.lim_excProd



      RESULT:



      enter image description here







      javascript vue.js components vue-component vuetify.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 21:48









      NatarrNatarr

      99112




      99112






















          1 Answer
          1






          active

          oldest

          votes


















          1














          You are comparing Strings; "20" is larger than "100" because "2" is larger than "1" (the first character). Convert them to Number if you want to compare the numeric value:



          this.error = Number(this.lim_faltProd) >= Number(this.lim_excProd)





          console.log("20" >= "100")

          console.log(Number("20") >= Number("100"))








          share|improve this answer

























          • So if i want to do it in a if, i MUST use Number() too?

            – Natarr
            Nov 13 '18 at 21:54











          • If you want to compare the two values in a numeric sense, you need to use Number. Doesn't matter where you do it as long as it's still in javascript.

            – Psidom
            Nov 13 '18 at 21:56












          • Thank you! i'll flag this as solved. Is there any way to store directly the value number and not to store it as strings?.

            – Natarr
            Nov 13 '18 at 21:59












          • You can do the conversion when your first initialize your data. i.e. in data () lim_faltProd: Number(this.lim_falt), lim_excProd: Number(this.lim_exc) You can also check here and see how to declare your props with specific types.

            – Psidom
            Nov 13 '18 at 22:01












          • Thank you!, i'll check it

            – Natarr
            Nov 13 '18 at 22:20










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290020%2fsimple-comparing-throw-wrong-result-vue%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You are comparing Strings; "20" is larger than "100" because "2" is larger than "1" (the first character). Convert them to Number if you want to compare the numeric value:



          this.error = Number(this.lim_faltProd) >= Number(this.lim_excProd)





          console.log("20" >= "100")

          console.log(Number("20") >= Number("100"))








          share|improve this answer

























          • So if i want to do it in a if, i MUST use Number() too?

            – Natarr
            Nov 13 '18 at 21:54











          • If you want to compare the two values in a numeric sense, you need to use Number. Doesn't matter where you do it as long as it's still in javascript.

            – Psidom
            Nov 13 '18 at 21:56












          • Thank you! i'll flag this as solved. Is there any way to store directly the value number and not to store it as strings?.

            – Natarr
            Nov 13 '18 at 21:59












          • You can do the conversion when your first initialize your data. i.e. in data () lim_faltProd: Number(this.lim_falt), lim_excProd: Number(this.lim_exc) You can also check here and see how to declare your props with specific types.

            – Psidom
            Nov 13 '18 at 22:01












          • Thank you!, i'll check it

            – Natarr
            Nov 13 '18 at 22:20















          1














          You are comparing Strings; "20" is larger than "100" because "2" is larger than "1" (the first character). Convert them to Number if you want to compare the numeric value:



          this.error = Number(this.lim_faltProd) >= Number(this.lim_excProd)





          console.log("20" >= "100")

          console.log(Number("20") >= Number("100"))








          share|improve this answer

























          • So if i want to do it in a if, i MUST use Number() too?

            – Natarr
            Nov 13 '18 at 21:54











          • If you want to compare the two values in a numeric sense, you need to use Number. Doesn't matter where you do it as long as it's still in javascript.

            – Psidom
            Nov 13 '18 at 21:56












          • Thank you! i'll flag this as solved. Is there any way to store directly the value number and not to store it as strings?.

            – Natarr
            Nov 13 '18 at 21:59












          • You can do the conversion when your first initialize your data. i.e. in data () lim_faltProd: Number(this.lim_falt), lim_excProd: Number(this.lim_exc) You can also check here and see how to declare your props with specific types.

            – Psidom
            Nov 13 '18 at 22:01












          • Thank you!, i'll check it

            – Natarr
            Nov 13 '18 at 22:20













          1












          1








          1







          You are comparing Strings; "20" is larger than "100" because "2" is larger than "1" (the first character). Convert them to Number if you want to compare the numeric value:



          this.error = Number(this.lim_faltProd) >= Number(this.lim_excProd)





          console.log("20" >= "100")

          console.log(Number("20") >= Number("100"))








          share|improve this answer















          You are comparing Strings; "20" is larger than "100" because "2" is larger than "1" (the first character). Convert them to Number if you want to compare the numeric value:



          this.error = Number(this.lim_faltProd) >= Number(this.lim_excProd)





          console.log("20" >= "100")

          console.log(Number("20") >= Number("100"))








          console.log("20" >= "100")

          console.log(Number("20") >= Number("100"))





          console.log("20" >= "100")

          console.log(Number("20") >= Number("100"))






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 21:54

























          answered Nov 13 '18 at 21:52









          PsidomPsidom

          123k1283125




          123k1283125












          • So if i want to do it in a if, i MUST use Number() too?

            – Natarr
            Nov 13 '18 at 21:54











          • If you want to compare the two values in a numeric sense, you need to use Number. Doesn't matter where you do it as long as it's still in javascript.

            – Psidom
            Nov 13 '18 at 21:56












          • Thank you! i'll flag this as solved. Is there any way to store directly the value number and not to store it as strings?.

            – Natarr
            Nov 13 '18 at 21:59












          • You can do the conversion when your first initialize your data. i.e. in data () lim_faltProd: Number(this.lim_falt), lim_excProd: Number(this.lim_exc) You can also check here and see how to declare your props with specific types.

            – Psidom
            Nov 13 '18 at 22:01












          • Thank you!, i'll check it

            – Natarr
            Nov 13 '18 at 22:20

















          • So if i want to do it in a if, i MUST use Number() too?

            – Natarr
            Nov 13 '18 at 21:54











          • If you want to compare the two values in a numeric sense, you need to use Number. Doesn't matter where you do it as long as it's still in javascript.

            – Psidom
            Nov 13 '18 at 21:56












          • Thank you! i'll flag this as solved. Is there any way to store directly the value number and not to store it as strings?.

            – Natarr
            Nov 13 '18 at 21:59












          • You can do the conversion when your first initialize your data. i.e. in data () lim_faltProd: Number(this.lim_falt), lim_excProd: Number(this.lim_exc) You can also check here and see how to declare your props with specific types.

            – Psidom
            Nov 13 '18 at 22:01












          • Thank you!, i'll check it

            – Natarr
            Nov 13 '18 at 22:20
















          So if i want to do it in a if, i MUST use Number() too?

          – Natarr
          Nov 13 '18 at 21:54





          So if i want to do it in a if, i MUST use Number() too?

          – Natarr
          Nov 13 '18 at 21:54













          If you want to compare the two values in a numeric sense, you need to use Number. Doesn't matter where you do it as long as it's still in javascript.

          – Psidom
          Nov 13 '18 at 21:56






          If you want to compare the two values in a numeric sense, you need to use Number. Doesn't matter where you do it as long as it's still in javascript.

          – Psidom
          Nov 13 '18 at 21:56














          Thank you! i'll flag this as solved. Is there any way to store directly the value number and not to store it as strings?.

          – Natarr
          Nov 13 '18 at 21:59






          Thank you! i'll flag this as solved. Is there any way to store directly the value number and not to store it as strings?.

          – Natarr
          Nov 13 '18 at 21:59














          You can do the conversion when your first initialize your data. i.e. in data () lim_faltProd: Number(this.lim_falt), lim_excProd: Number(this.lim_exc) You can also check here and see how to declare your props with specific types.

          – Psidom
          Nov 13 '18 at 22:01






          You can do the conversion when your first initialize your data. i.e. in data () lim_faltProd: Number(this.lim_falt), lim_excProd: Number(this.lim_exc) You can also check here and see how to declare your props with specific types.

          – Psidom
          Nov 13 '18 at 22:01














          Thank you!, i'll check it

          – Natarr
          Nov 13 '18 at 22:20





          Thank you!, i'll check it

          – Natarr
          Nov 13 '18 at 22:20

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53290020%2fsimple-comparing-throw-wrong-result-vue%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線