🔒 Closed c# quantity

Status
Not open for further replies.

anonymous_d

Established
586841
pano po kaya yung ganyang error patulong po sa nakakaalam
 
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
  • 369
    Views
  • 4
    Participants
Last reply from:
pixkit

Trending Topics

Online now

Members online
1,112
Guests online
1,890
Total visitors
3,002

Forum statistics

Threads
2,278,231
Posts
28,981,809
Members
1,228,278
Latest member
Vishala
Back
Top