# [SOLVED]Check if player.posX ends with .99

## Recommended Posts

Hello, I'm looking for a way to check, if player's current X(or any axis really) ends with .99 and then fire an event.

My current code:

```double playerX = Math.floor(Minecraft.getMinecraft().thePlayer.posX);
double playerY = Math.floor(Minecraft.getMinecraft().thePlayer.posY);
double playerZ = Math.floor(Minecraft.getMinecraft().thePlayer.posZ);
double playerYaw = Minecraft.getMinecraft().thePlayer.rotationYaw;

if (String.format("%.2f", playerX) = endsWith(.99));
{
LogHelper.info("true");
}
```

##### Share on other sites

First:

`double playerX = Math.floor(Minecraft.getMinecraft().thePlayer.posX);`

The floor function maps a number to its largest preceeding integer (e.g. 29.99 -> 29.00), so you will have a value ending with .00.

Second:

```if (coordinate > 0) {
float v = coordinate - .99;
if (x = (int) x) {
// the player's positive coordinate ends with .99
}
} else {
float v = coordinate + .99;
if (x = (int) x) {
// the player's negative coordinate ends with .99
}
}
```

Note: if the coordinates have more than two digits after the decimal point, this code will mess up. If that is the case, be sure to truncate the floats.

##### Share on other sites

Hi

I think your sample code will work fine with a bit of tweaking

```
double playerXfloor = Math.floor(Minecraft.getMinecraft().thePlayer.posX);
double playerXremainder = Minecraft.getMinecraft().thePlayer.posX - playerXfloor;
if (String.format("%.2f", playerXremainder ).contains(".99"));
{
LogHelper.info("true");
}
```

For positive numbers, this will trigger for any numbers between x.985 and x.9949999999

For negative numbers, this will trigger at numbers ending in 0.01 instead of 0.99

Is that what you want?

I'm with DieSieben though, are you sure that's really the effect you're looking for?

-TGG

##### Share on other sites

Uhm... that sounds like weird request. Why do you want to do that?

The mod is supposed to help me do 4 block jumps since I have been getting worse at them

##### Share on other sites

And... why do you need to check for ".99" then?

To check if my coordinate ends with .99 and then jump to guarantee successful jump

##### Share on other sites

Then I don't think you want to check "ends with .99". I think you want to check "first two decimal places are 99".

Then it's all just maths:

```double absPos = Math.abs(player.posX);
boolean endsWith99 = (int) ((absPos - (int) absPos) * 100) == 99;```

Alright, I had to make it check for just 9 and add booleans for 8 and 7, but it works and does exactly what I want.

Thank you very much!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• ### Posts

• Add the crash-report or latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here
• Hello everyone!! I have a problem with the game clashed exit code 1 . I have tried the basic solutions that I know from the internet: 1.) delete and reinstall JAVA 8 & JAVA 17 2.) delete and reinstall Minecraft 3.) delete all resourcepacks,mods,and shaderpacks and 4. ) reset my PC which doesn't work in every way. But I noticed that when I installed Minecraft forge, there were no mods folder in the .Minecraft folder sometimes. Can you help me solve this problem, please?   https://ibb.co/N159q70 https://ibb.co/4Jz79qs
• Hello everyone!! I have a problem with the game crashed exit code 1 . I have tried the basic solutions that I know from the internet: 1.) delete and reinstall JAVA 8 & JAVA 17 2.) delete and reinstall Minecraft 3.) delete all resourcepacks,mods,and shaderpacks and 4. ) reset my PC which doesn't work in every way. But I noticed that when I installed Minecraft forge 1.20.6 , there were no mods folder in the .Minecraft folder sometimes. Can you help me solve this problem, please? https://ibb.co/4Jz79qs https://ibb.co/N159q70
• sup so im having the same problem but i dont have any mods or modpacks on forge idk what to do always keep saying exit code -805306369 i put more rams on the game but still crashes on the loading screen when a open the game if somebody can help.

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...