a3deluxe Posted March 25, 2015 at 01:49 PM Report Share #580198 Posted March 25, 2015 at 01:49 PM Boas, Tenho uma textbox com um valor por exemplo 2000, queria retirar sempre 2 casas decimais sempre que aparece-se algum valor na textbox, neste caso ficaria 20. Tentei com o Match.Round mas não consegui. Alguém podia dar uma ajudinha. Obrigado Link to comment Share on other sites More sharing options...
vikcch Posted March 25, 2015 at 01:53 PM Report Share #580199 Posted March 25, 2015 at 01:53 PM 2000 não tem casas decimais... se queres tirar os 2 ultimos digitos divides por 100... e arredondasou converte para inteiro Link to comment Share on other sites More sharing options...
bioshock Posted March 25, 2015 at 02:01 PM Report Share #580201 Posted March 25, 2015 at 02:01 PM O Math.Round só funciona para valores decimais. string value = "203050"; MessageBox.Show(value.Substring(0, value.Length - 2).ToString()); Link to comment Share on other sites More sharing options...
a3deluxe Posted March 25, 2015 at 03:06 PM Author Report Share #580205 Posted March 25, 2015 at 03:06 PM Como poderia fazer? Link to comment Share on other sites More sharing options...
a3deluxe Posted March 25, 2015 at 10:13 PM Author Report Share #580222 Posted March 25, 2015 at 10:13 PM Para colocar uma virgula nos 2 últimos dígitos? Link to comment Share on other sites More sharing options...
vikcch Posted March 25, 2015 at 11:43 PM Report Share #580225 Posted March 25, 2015 at 11:43 PM queres inserir 205 na textbox e ficar 2,05? no evento lost focus ou leave da textbox: textbox.text = textbox.text.insert(textbox.text.length-2,",") deve dar erro se a textbox só tiver 1 digito assim se inserires 2000 vai ficar 20,00 Link to comment Share on other sites More sharing options...
a3deluxe Posted March 26, 2015 at 03:14 AM Author Report Share #580229 Posted March 26, 2015 at 03:14 AM (edited) vikcchm, Obrigado Testei na leitura de um ficheiro TXT com um valor e funcionou. Agora queria usar o mesmo código para ler uns numero de um Ficheiro Binário, e não funcionou. Aqui neste código: // For Each drive As DriveInfo In DriveInfo.GetDrives() Dim FILE_NAME As String = String.Format("D:\DADOS", drive.Name) If System.IO.File.Exists(FILE_NAME) = True Then Dim data() As Byte = File.ReadAllBytes(FILE_NAME) Dim palavras As New List(Of String) Dim palavra As String = "" ' For Each b As Byte In data If b = 0 Then ' palavras.Add(palavra.Replace("N", "")) palavra = "" ElseIf b >= 32 Then palavra = palavra + Chr(b) End If Next palavras(5) = TextBox7.Text palavras(7) = TextBox8.Text encontrou = True Exit For End If Next If Not encontrou Then MsgBox("Ficheiro não Existe") End If Alguém para dar uma ajudinha? Edited March 26, 2015 at 03:34 AM by a3deluxe Link to comment Share on other sites More sharing options...
a3deluxe Posted March 27, 2015 at 11:22 PM Author Report Share #580372 Posted March 27, 2015 at 11:22 PM (edited) Onde poderia colocar no meu código esta parte // textbox.text = textbox.text.insert(textbox.text.length-2,",") para colocar a virgula na duas ultimas casas decimais. Num ficheiro TXT funciona bem, na leitura de um ficheiro em Binário não esta a funcionar. Edited March 27, 2015 at 11:22 PM by a3deluxe Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now