🔒 Closed c# quantity

Status
Not open for further replies.
lagay ka default value/text dun sa textbox...
ex. 0...
wala kasing string na icoconvert dun sa parse function since walang value dun sa textbox...
 
It doesn't make sense that you declared double type variables and you are parsing the input strings as int.

Here take a look of the difference You do not have permission to view the full content of this post. Log in or register now. . I'm not a C# developer but the idea is similar with other languages like Java.

These will work:

double to double
Code:
using System;

class MainClass {
  public static void Main (string[] args) {
    Console.WriteLine ("Hello World");

    double amt;
    double ans;
    double qty;

    amt = double.Parse("100.00");
    qty = double.Parse("51.50");
    ans = amt * qty;

    Console.WriteLine(ans);
  }
}


int to int
Code:
using System;

class MainClass {
  public static void Main (string[] args) {
    Console.WriteLine ("Hello World");

    int amt;
    int ans;
    int qty;

    amt = int.Parse("100");
    qty = int.Parse("51");
    ans = amt * qty;

    Console.WriteLine(ans);
  }
}

But these will fail and will throw
Unhandled Exception:
System.FormatException: Input string was not in a correct format.


Code:
     int amt;
    int ans;
    int qty;

    amt = int.Parse("100");
    qty = int.Parse("51.50");
    ans = amt * qty;

    Console.WriteLine(ans);
    
    
    # Or
    
    double amt;
    double ans;
    double qty;

    amt = int.Parse("100.00");
    qty = int.Parse("51.50");
    ans = amt * qty;

    Console.WriteLine(ans);

The error matches on the screenshot you provided.
 
Status
Not open for further replies.

About this Thread

  • 8
    Replies
  • 381
    Views
  • 4
    Participants
Last reply from:
pixkit

Trending Topics

Online now

Members online
1,152
Guests online
1,639
Total visitors
2,791

Forum statistics

Threads
2,291,261
Posts
29,069,649
Members
1,210,798
Latest member
joferson201
Back
Top