-
Nov 9th, 2016, 05:13 PM
#1
Thread Starter
Hyperactive Member
[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
-
Nov 9th, 2016, 05:56 PM
#2
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?
-
Nov 9th, 2016, 06:11 PM
#3
Thread Starter
Hyperactive Member
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)
-
Nov 9th, 2016, 07:46 PM
#4
Hyperactive Member
Re: How to use Round in this code:
Originally Posted by AceDuk
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:
TextBox1.Text = Math.Round(Val(TextBox1.Text), 2).ToString
-
Nov 9th, 2016, 08:27 PM
#5
Re: How to use Round in this code:
Originally Posted by AceDuk
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?
-
Nov 10th, 2016, 06:24 AM
#6
Thread Starter
Hyperactive Member
Re: How to use Round in this code:
Originally Posted by Vexslasher
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:
TextBox1.Text = Math.Round(Val(TextBox1.Text), 2).ToString
i tried like this but i got result 0
Last edited by AceDuk; Nov 10th, 2016 at 06:27 AM.
-
Nov 10th, 2016, 06:58 AM
#7
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?
-
Nov 10th, 2016, 08:40 AM
#8
Re: How to use Round in this code:
Originally Posted by AceDuk
i tried like this but i got result 0
The code in your picture worked for me.
-
Nov 10th, 2016, 04:59 PM
#9
Re: How to use Round in this code:
Originally Posted by topshot
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.
-
Nov 10th, 2016, 05:11 PM
#10
Re: How to use Round in this code:
Originally Posted by jmcilhinney
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
-
Nov 10th, 2016, 05:21 PM
#11
Thread Starter
Hyperactive Member
Re: How to use Round in this code:
-
Nov 10th, 2016, 07:35 PM
#12
Re: How to use Round in this code:
Originally Posted by topshot
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|