x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Float problem

Hello!

I have made a function which takes a Speed Base Value (float) and a Modifier Value (float), multiply both, then divides the result per 100 and finally, I add the result to the Speed Base Value so I get a base number + a percentage. I add the screenshot. I add the screenshot.

The thing is that the total result I get returns a float with a high number of decimals while I only want to get 2 decimals maximum. I add a second screenshot of what I get making a 2% of a Speed Base Value of 180 which returns a total of 183.600006

I add a second screenshot

So I have tried tons of ways to make that number have just two decimals, I dont need more than two. I add a third screenshot of some of the ways I tried with no success.

I add a third screenshot

I could get just two decimals when showing on the HUD, applying the node ToText(float) directly to the TextBox but thats not what I really want. I just want to get those 2 decimals on the float value itself.

What is really happening? Why I can not get just two decimals? Any ideas?

Thank you all

Product Version: UE 4.19
Tags:
modifiers.jpg (167.7 kB)
statsts.jpg (190.5 kB)
more ▼

asked Feb 06 '19 at 01:57 AM in Blueprint Scripting

avatar image

gon.
47 2 10 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

Like this......you have to expand the "to text" node, it gives all these extra options. Set "max fractional digits" to 2 for 2 decimals. Then convert text to string, and string back to the nice clean rounded float. (Text to float directly isn't compatible)

alt text

float-rounding.jpg (72.4 kB)
more ▼

answered Feb 06 '19 at 04:55 AM

avatar image

Nebula Games Inc
5.4k 28 9 14

avatar image Nebula Games Inc Feb 06 '19 at 02:51 PM

Notice my input value? 1.55555? I printed that off and it showed 1.56..... this node as shown definitely works. You must be changing your float value somewhere else after you round and before you display it to the screen. Show me screen shots of how you actually put this into your HUD, what you have above is just a function with a return node. Modifying the float after that could be causing your issue

avatar image gon. Feb 06 '19 at 05:28 PM

Have been controlling the error using Print Strings nodes and I noticed something weird. The problem is when you convert String variable to Float variable.

So...

If I use Print String directly with the String Variable like this:

alt text

I get the proper right number, 183.60

But when I use Print String with the Float Variable like this:

alt text

I get the wrong weird number, 183.600006

alt text

opcion2.jpg (218.4 kB)
opcion1.jpg (217.8 kB)
screenshot1.jpg (26.0 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi! Thanks for your answer. I already checked that node and... keeps giving me the same result of 183.600006 I can not understand why always returns all that amount of decimals!! Have no sense.

more ▼

answered Feb 06 '19 at 02:14 PM

avatar image

gon.
47 2 10 10

avatar image Nebula Games Inc Feb 06 '19 at 02:47 PM

Try not to make new answers, add comments below my answer it keeps things neat and easy to read for others.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Okey, after assimilating its just the nature of the Float Variables, I just decided to IGNORE those 0.000006 as a part of how it really works. If I want to show a float value in a TextBox or HUD and get simmilar numbers, I will use ToText (float) node and limit decimals as you said or using any other ways I already listed before.

Thank you.

Links about Float Variables:

https://floating-point-gui.de/

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html?fbclid=IwAR3VYpB_QizBBwe_HwsnJvDo_hxpwFLCj1ZwKFx-sGajY09WNPYAB2B_7tY

more ▼

answered Feb 06 '19 at 10:24 PM

avatar image

gon.
47 2 10 10

avatar image Rakosman Feb 08 '19 at 12:39 AM

This is basically it. A float cannot represent some numbers. If you need to preserve it as a number rather than text for whatever reason you can also store the number and the decimal separately with two integers. Of course, if you merge them back into float you will have the same problem.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

why not use integer?

more ▼

answered Feb 07 '19 at 01:39 PM

avatar image

marvelmaster
41 2 7 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question