c# - Xamarin Forms 条目文本不返回数字
问题描述
我对编程很陌生。我正在尝试将条目文本存储在浮点变量中,然后计算基本百分比并将其显示在标签下方。代替标签内的变量,它打印 NaN。如果我改用整数,它表示我正在尝试除以零,这告诉我从 entry 读取的文本不返回任何内容。
这可能是什么原因?
public partial class GoalTrackerPage : ContentPage
{
float goal = 0.0000f;
float done = 0.0000f;
float progress = 0.0000f;
public GoalTrackerPage ()
{
InitializeComponent ();
g1EntryGoal = new Entry();
g1EntryDone = new Entry();
g1PrBar = new ProgressBar();
}
private void add1_Clicked(object sender, EventArgs e)
{
GoalStatusLabelView();
}
private void GoalStatusLabelView ()
{
progress = done / goal * 100.0000f;
g1StatusLabel.Text = "The Goal is at " + progress;
}
private void g1EntryGoal_Completed(object sender, EventArgs e)
{
goal = float.Parse(g1EntryGoal.Text ?? "0");
}
private void g1EntryDone_Completed(object sender, EventArgs e)
{
done = float.Parse(g1EntryDone.Text ?? "0");
}
解决方案
{
progress = done / goal * 100.0000f;
g1StatusLabel.Text = "The Goal is at " + progress;
}
结果基本上为零,并且由于它带有双精度值,因此它将在 g1StatusLabel.Text 处返回 NaN。
也许这可以为处理 NaN 结果提供更多信息。
推荐阅读
- mysql - 错误:“列 'date_created' 不能为空”尝试创建实体时
- javascript - 我们如何发送一个隐藏在 php 中的 jquery 金额以供另一个页面检索金额值?
- performance - O*(c^n) 代表什么?它与 log * 有什么关系吗?(如果是这样 - 如何?)
- sql - Presto SQL 窗口聚合回顾 x 小时/分钟/秒
- c# - NullReferenceException 串行通信接收数据 C#
- css - 在 SCSS 中迭代列表数据类型
- cookies - 如何处理多个 CORS 请求的 cookie
- javascript - 如何判断删除的文件是否是文件夹?
- python - 当我们在 django 中使用 on_delete=models.CASCADE 会发生什么
- c# - C# MediaCapture UnuthorizedAccessException 或 Windows 更新后不支持的格式