Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.
Avatar
Anon
Člen
Avatar
Anon:26.12.2018 14:07

Nejde mi , aby mi to počítalo i s desetinou čárkou.

Zkusil jsem: Hledal jsem na internetu, nefungovalo to.

Chci docílit: Chci,aby mi to konečně počítalo s desetinou čárkou.

kod:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;



namespace WindowsFormsApplication22
{


    public partial class Form1 : Form

    {


        int vysledek = 0;


        public Form1()


        {
            InitializeComponent();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {




            int cislo1 = int.Parse(txtCislo1.Text);
            int cislo2 = int.Parse(txtCislo2.Text);
            int cislo3 = int.Parse(txtCislo3.Text);

            int vysledek  = (cislo1 - cislo2) / cislo3;

            txtVysledek.Text = vysledek.ToString();







        }
    }
}

Designer :

namespace WindowsFormsApplication22
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.txtCislo1 = new System.Windows.Forms.TextBox();
            this.txtCislo2 = new System.Windows.Forms.TextBox();
            this.txtCislo3 = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.txtVysledek = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            //
            // contextMenuStrip1
            //
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(121, 197);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(89, 30);
            this.button1.TabIndex = 2;
            this.button1.Text = "vypocitat";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 106);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(166, 13);
            this.label1.TabIndex = 5;
            this.label1.Text = "Proud protékající diodou ID [mA]:";
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(9, 57);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(122, 13);
            this.label2.TabIndex = 6;
            this.label2.Text = "Napětí na diodě UD [V]:";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(9, 5);
            this.label3.Name = "label3";
            this.label3.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
            this.label3.Size = new System.Drawing.Size(105, 13);
            this.label3.TabIndex = 7;
            this.label3.Text = "Napětí zdroje UZ [V]";
            //
            // txtCislo1
            //
            this.txtCislo1.Location = new System.Drawing.Point(12, 21);
            this.txtCislo1.Multiline = true;
            this.txtCislo1.Name = "txtCislo1";
            this.txtCislo1.Size = new System.Drawing.Size(195, 19);
            this.txtCislo1.TabIndex = 0;
            //
            // txtCislo2
            //
            this.txtCislo2.Location = new System.Drawing.Point(12, 73);
            this.txtCislo2.Multiline = true;
            this.txtCislo2.Name = "txtCislo2";
            this.txtCislo2.Size = new System.Drawing.Size(195, 19);
            this.txtCislo2.TabIndex = 10;
            //
            // txtCislo3
            //
            this.txtCislo3.Location = new System.Drawing.Point(15, 122);
            this.txtCislo3.Multiline = true;
            this.txtCislo3.Name = "txtCislo3";
            this.txtCislo3.Size = new System.Drawing.Size(195, 19);
            this.txtCislo3.TabIndex = 11;
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(12, 156);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(75, 13);
            this.label4.TabIndex = 12;
            this.label4.Text = "Vysledek R[Ω]";
            //
            // txtVysledek
            //
            this.txtVysledek.Location = new System.Drawing.Point(15, 172);
            this.txtVysledek.Multiline = true;
            this.txtVysledek.Name = "txtVysledek";
            this.txtVysledek.Size = new System.Drawing.Size(195, 19);
            this.txtVysledek.TabIndex = 13;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(218, 232);
            this.Controls.Add(this.txtVysledek);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.txtCislo3);
            this.Controls.Add(this.txtCislo2);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.txtCislo1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.Name = "Form1";
            this.RightToLeftLayout = true;
            this.Text = "výpočet rezistorů pro led";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion
        private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.TextBox txtCislo1;
        private System.Windows.Forms.TextBox txtCislo2;
        private System.Windows.Forms.TextBox txtCislo3;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox txtVysledek;
    }
}
 
Odpovědět
26.12.2018 14:07
Avatar
Odpovídá na Anon
Matúš Olejník:26.12.2018 14:20

Čo tak použiť napr. dátový typ double namiesto int pre desatinné čísla ;)

Akceptované řešení
+20 Zkušeností
Řešení problému
Nahoru Odpovědět
26.12.2018 14:20
/* I am not sure why this works but it fixes the problem */
Avatar
Odpovídá na Anon
Honza Prosecký:26.12.2018 14:51

Musis jedno z cisel pretypovat napr na float. (Float) 1/2

 
Nahoru Odpovědět
26.12.2018 14:51
Avatar
Anon
Člen
Avatar
Odpovídá na Matúš Olejník
Anon:26.12.2018 15:08

Děkuji za odpověď.Už to fakčí :)

 
Nahoru Odpovědět
26.12.2018 15:08
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 4 zpráv z 4.