How to add commas to numbers in Unity using C# really quickly and easily. Just one line of code!!!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today i'm just going to do a very quick tutorial on how to add commas to large numbers this is something i've seen people do some quite complicated ways but it's actually really simple using the standard numeric format strings there's a particular one called the numeric format specifier which perfectly fits the job so let's make a script i'm going to make it in the scripts folder i'm just going to call it show float with commas double click to open it in visual studio now we're not going to need our update function and here i'm going to make a number that we're going to display i'm going to make it quite large and have some decimal points and put an f because it's a float now to display this i want to put 789 comma 332.33 so i'm going to just put this into the console rather than putting it into the level i'm going to go debug.log i'm going to do the number to display and i'm going to use two string i'm going to write n2 where 2 is the number of decimal places that you want to show i'm gonna save this and we'll go back to unity let's just drop the script on our main camera and hit play and here you can see it's gone 789 comma 332 0.3 and this will work with any number that you put in and the number of decimal places that you set and so that's how easy it is to add commas so don't try and do it a complicated way just try and do it this way and if you've got other sorts of things you want to do with numbers to display them definitely look up the standard numeric format strings and c sharp because there's lots and lots of different things you can do with it i hope this was helpful for some people if you did please feel free to like subscribe or comment it's really appreciated hope you're having fun with your game development you
Info
Channel: Destined To Learn
Views: 2,180
Rating: undefined out of 5
Keywords:
Id: BjuSdLzLktA
Channel Id: undefined
Length: 2min 57sec (177 seconds)
Published: Thu Mar 31 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.