PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2010 [RESOLVED] How to use Round in this code:-VBForums
Results 1 to 12 of 12

Thread: [RESOLVED] How to use Round in this code:

  1. #1

    Thread Starter
    Hyperactive Member AceDuk's Avatar
    Join Date
    Jan 2016
    Location
    Macedonia
    Posts
    465

    Resolved [RESOLVED] How to use Round in this code:

    Code:
    TextBox1.Text = Val(currencyAmount.Text) * Val(mainText.Text)
    i want calculated data in textbox1 to be round like that:
    if result on textbox is let's say 3.1433 round to be 3.14

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,483

    Re: How to use Round in this code:

    I just searched the web for "vb.net round number to 2 decimal places" and had the answer to your question in less than 10 seconds. Why exactly are you unable to do the same?

  3. #3

    Thread Starter
    Hyperactive Member AceDuk's Avatar
    Join Date
    Jan 2016
    Location
    Macedonia
    Posts
    465

    Re: How to use Round in this code:

    Before i ask this question i try with this code but doesn't work: Textbox1.text = Math.Round(Val(Textbox1.text), 2)

  4. #4
    Hyperactive Member Vexslasher's Avatar
    Join Date
    Feb 2010
    Posts
    429

    Re: How to use Round in this code:

    Quote Originally Posted by AceDuk View Post
    Before i ask this question i try with this code but doesn't work: Textbox1.text = Math.Round(Val(Textbox1.text), 2)
    Your very close you just needed to convert it from an integer to a string so that the textbox can accept the information.
    vb.net Code:
    1. TextBox1.Text = Math.Round(Val(TextBox1.Text), 2).ToString

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,483

    Re: How to use Round in this code:

    Quote Originally Posted by AceDuk View Post
    Before i ask this question i try with this code but doesn't work: Textbox1.text = Math.Round(Val(Textbox1.text), 2)
    So you should have said that in the first place, and you also should have explained how the result of that differed from what you expected.

    As for the code, why would you put a value into the TextBox, then take it out, then round it, then put it back in again? Why wouldn't you round the value before putting it into the Textbox in the first place?

  6. #6

    Thread Starter
    Hyperactive Member AceDuk's Avatar
    Join Date
    Jan 2016
    Location
    Macedonia
    Posts
    465

    Question Re: How to use Round in this code:

    Quote Originally Posted by Vexslasher View Post
    Your very close you just needed to convert it from an integer to a string so that the textbox can accept the information.
    vb.net Code:
    1. TextBox1.Text = Math.Round(Val(TextBox1.Text), 2).ToString
    i tried like this but i got result 0
    Name:  untitled.jpg
Views: 42
Size:  14.6 KB
    Last edited by AceDuk; Nov 10th, 2016 at 06:27 AM.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,483

    Re: How to use Round in this code:

    Was there anything in TextBox1 to begin with? If not then that's exactly what you should have got. Did you bother to read post #5?

  8. #8
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,191

    Re: How to use Round in this code:

    Quote Originally Posted by AceDuk View Post
    i tried like this but i got result 0
    The code in your picture worked for me.

  9. #9
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,483

    Re: How to use Round in this code:

    Quote Originally Posted by topshot View Post
    The code in your picture worked for me.
    That code will only work if there's already something in TextBox1. If the calculation has not already been performed and the unrounded result put in TextBox1 then code to round what's in TextBox1 is useless. Of course, as I have already said, what's the point of calculating a result, putting it in TextBox1, getting it out of TextBox1, rounding it and then putting it back into TextBox1 when you can simply do the calculation, round the result and then pout that final result into TextBox1? I seem to speaking into the void though, as no one appears to be listening.

  10. #10
    Frenzied Member
    Join Date
    Dec 2014
    Location
    VB6 dinosaur land
    Posts
    1,191

    Re: How to use Round in this code:

    Quote Originally Posted by jmcilhinney View Post
    That code will only work if there's already something in TextBox1.
    Well, that's obvious, but he has 0.45 in TextBox1 in the picture. Ignoring the validation issues, yes, it would be better written as
    Code:
    TextBox3.Text = Math.Round(Val(TextBox1.Text) * Val(TextBox2.Text), 2).ToString

  11. #11

    Thread Starter
    Hyperactive Member AceDuk's Avatar
    Join Date
    Jan 2016
    Location
    Macedonia
    Posts
    465

    Re: How to use Round in this code:

    it's working thank you!

  12. #12
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,483

    Re: How to use Round in this code:

    Quote Originally Posted by topshot View Post
    Well, that's obvious, but he has 0.45 in TextBox1 in the picture.
    But clearly the code has changed since that screenshot was taken, so assuming that the TextBox still contains what it did then is a big leap of faith.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width