Reputation: 523
Sorry, noob question I'm searching for how to limit the amount of decimal points printed. I found this:
print(price.toStringAsFixed(2)); // which worked great in another script
but how do I limit to 1 decimal point in the script below? I'm getting 14 decimal places :)
String inTemp = stdin.readLineSync();
int temp = int.parse(inTemp);
switch (selection) {
case 'A':
print('$temp degrees Celcius is ${temp * 1.8 + 32} degrees Fahrenheit');
*I'm sure it's something obvious but I can't figure it out.
Cheers for any help.
String inTemp = stdin.readLineSync();
int temp = int.parse(inTemp);
num temp1 = (temp * 1.8 + 32);
num temp2 = ((temp - 32) / 1.8);
switch (selection) {
case 'A':
print('$temp degrees Celcius is ${temp1.toStringAsFixed(1)} degrees Fahrenheit');
Upvotes: 2
Views: 2205
Reputation: 71828
You do the same thing to the number, just inside the ${...}
:
case 'A':
print('$temp degrees Celcius is ${(temp * 1.8 + 32).toStringAsFixed(1)}'
' degrees Fahrenheit');
Upvotes: 2