I have tried everything, but I cannot seem to get it correct. I have been trying to make a vertical mps indicator for my jet planes, I was easily able to figure that out, but it always had way to many decimals, and that was very annoying, I just wanted one or two decimal places, not 8. Can someone help me round!
Tags
Question4 Comments
- Log in to leave a comment
-
Mod sflanker
There are several ways, but if you are doing this for display purposes then the best way is to use the
format
expression. Theformat
expression takes a variable number of arguments. The first argument is a composite format string (with a few limitations). The remaining arguments are parameters that will be interpolated into that format string. You can follow the link for details, but a quick TLDR: composite format strings are strings that contain place holders for values to be inserted a place holder consists of an open curly brace, a number which is the index of the value to insert, an optional format specified, and a closing curly brace. A format specifier starts with a colon which may either be followed by a letter indicating a special type of format (sometimes followed by a numeric parameter), or a custom numeric format string. Some common special format types aren
which is a number with thousands separators,f
which is a number without thousands separators, ande
which is for scientific notations. All of these can be followed by a number specifying the number of decimal places (i.e.f2
is a number without thousands separators and with two decimal places). Custom numeric format strings generally take the form#,##0.00
or0000.0
where#
is a place holder for a digit if need and0
is a place holder for a digit which will be present whether needed or not (i.e. it pads small numbers with leading zeros).⠀
To sum up:
format [Example: {0:n2} {1}] [1234.5678] [meters]
will return "Example: 1,234.57 meters" -
157 RyanRyRy
@Insanity thanks so much, o already tried the format thing, but I never figured out how that worked, it would be helpful if you explain it a bit to me or showed me where i could find more information. Thank so much with your answer, it helped me out a ton!
-
10.9k Insanity
You could multiply by 100 round and then divide by 100 (10 for each if you want just one decimal place). Alternatively you could use the 'format' block which allows for rounding to a certain decimal place.
@sflanker How do you do the custom format with ##. I tried it but did not get any extra zeroes in front of my number.
Nevermind, I reread more carefully and used zeroes instead and it worked.