本文介绍了我尝试将数据类型double转换为String..Help时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我尝试了以下内容......I have tried the following...public static void String Detail(){ double minute = duration /60; return minute.ToString();}推荐答案public static void String Detail() 我甚至对这个编译感到惊讶。你的方法的返回类型是什么? void或String? 另一个问题是:您的问题是从持续时间中查找分钟数,还是显示双数字的字符串表示? 如果你正在努力计算几秒钟的分钟数,那肯定是:I'm even surprised this compiles. What is the return type of your method? void or String?Another question is: is your issue finding the number of minutes from a duration, or displaying a string representation of a double number?If you're struggling with computing the number of minutes from a number of seconds, then it's definitely:public static double minutesFromSeconds(int seconds) { return seconds / 60.0; // Here we use the 60.0 notation so that we compute a real division, // not an integer one} 如果您的问题是获得双数字的字符串表示,那么它就像以下一样简单:If your issue is getting a string representation of a double number, then it is as trivial as:String result = minutes.ToString(); 重要的是:永远不要使用任何数字作为字符串。仅在需要将其呈现给用户时才使用字符串表示。使用字符串来处理代码中的数字是最糟糕的做法之一。The important thing is: never work with any number as a string. Only use a string representation when you need to present it to the user. Using strings to handle numbers in code is one of the worst practices ever. 这篇关于我尝试将数据类型double转换为String..Help时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-24 09:58