AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Fload display (https://forums.alliedmods.net/showthread.php?t=208144)

EDUTz 02-10-2013 11:30

Fload display
 
How to display a float with only 2 decimals ?
Code:

new const XDAMAGE[11][] = {
        "1.0",
        "1.1",
        "1.2",
        "1.3",
        "1.4",
        "1.5",
        "1.6",
        "1.7",
        "1.8",
        "1.9",
        "2.0"
}
new Float: xdmg = str_to_float(XDAMAGE[g_level[id]])
ShowSyncHudMsg(id, g_HudMsgr, "Damage x %f", xdmg)

This will display: Damage x 1.2999999 (just an example)

ConnorMcLeod 02-10-2013 11:39

Re: Fload display
 
I think you are the first person who has ever asked this, so it would be useless trying to search.
I hope someone has the answer though.

Arkshine 02-10-2013 11:41

Re: Fload display
 
If you want to show value from your array, you don't need to convert to float.

ShowSyncHudMsg(id, g_HudMsgr, "Damage x %s", XDAMAGE[g_level[id]])

EDUTz 02-10-2013 12:04

Re: Fload display
 
10x arkshine, yes it was just a matter of display and that does the trick. Simple solutions are the best :))

Sylwester 02-10-2013 12:19

Re: Fload display
 
You call that simple solution? Storing float damage multipliers as strings? lol
PHP Code:

new Floatxdmg 1.0 0.1*g_level[id]
ShowSyncHudMsg(idg_HudMsgr"Damage x %.1f"xdmg


EDUTz 02-10-2013 13:01

Re: Fload display
 
what's wrong with that ? It's just for displaying that float as a string.
why should i do an extra calculation when it's just as simple as that ?

Sylwester 02-10-2013 13:18

Re: Fload display
 
Redundant code. Although you say it's just for displaying, aren't you using float multiplier to change damage in your plugin? Then why do you add unnecessary array of strings when you can use the same thing for multiplying damage and displaying multiplier value? Also imagine you want to edit the multipliers (you would have to edit every value in array to match actual multiplier - waste of time).

EDUTz 02-10-2013 16:02

Re: Fload display
 
Oh, i see what you mean. Thanks for helping ! :)


All times are GMT -4. The time now is 20:37.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.